From cfe80b6aa98ca4d00354b5ccbdae85e52c047326 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 11 Sep 2017 07:39:18 -0400 Subject: [PATCH] [msbuild][mac][ios] Fix referencing netstandard projects Building a XI or XM (Modern) project that references a netstandard 2.0 project with msbuild fails because of a missing reference to `netstandard.dll`. AppDelegate.cs(21,52): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The reason is that XI and XM (Modern) projects have `$(TargetFrameworkIdentifier) != .NETFramework`, so targets from `Microsoft.NET.Build.Extensions` which provide ns2.0 support don't get imported. `ImplicitlyExpandNETStandardFacades` in particular, which would have added a reference to `netstandard.dll`. `netstandard.dll` gets included as part of the facades expanded by `ImplicitlyExpandDesignTimeFacades`, but this gets skipped if the project does not have a `System.Runtime` dependent reference. Instead, we want to expand the facades if any reference depends on `System.Runtime` OR `netstandard`. And for that we scan all the references for a `netstandard` dependency using the `GetDependsOnNETStandard` task. Partially fixes bxc #58504 . --- ....Mac.Common.ImplicitFacade.msbuild.targets | 31 +++++++++++++++++- .../Xamarin.iOS.Common.targets | 32 +++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.ImplicitFacade.msbuild.targets b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.ImplicitFacade.msbuild.targets index 7c86a45e1062..e668f779cf2e 100644 --- a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.ImplicitFacade.msbuild.targets +++ b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.ImplicitFacade.msbuild.targets @@ -33,13 +33,42 @@ Copyright (c) 2017 Microsoft Corp. (www.microsoft.com) + + + + + + + + <_HasReferenceToSystemRuntime Condition="'$(DependsOnSystemRuntime)' == 'true' or '%(_ResolvedProjectReferencePaths.TargetPlatformIdentifier)' == 'Portable'">true + + true - + + + + + + <_DesignTimeFacadeAssemblies Include="%(DesignTimeFacadeDirectories.Identity)*.dll"/> <_DesignTimeFacadeAssemblies_Names Include="@(_DesignTimeFacadeAssemblies->'%(FileName)')"> diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets index 71c8b628ebc7..3c0c2782f7cd 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets @@ -155,14 +155,42 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. - + + + + + + + + <_HasReferenceToSystemRuntime Condition="'$(DependsOnSystemRuntime)' == 'true' or '%(_ResolvedProjectReferencePaths.TargetPlatformIdentifier)' == 'Portable' or '%(ReferenceDependencyPaths.Filename)' == 'System.Runtime'">true + + true - + + + + + + <_DesignTimeFacadeAssemblies Include="%(DesignTimeFacadeDirectories.Identity)*.dll"/>