From bf6dced714a592709cf836dbc74d4508a54ae6f7 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Fri, 15 May 2020 14:45:47 -0400 Subject: [PATCH 1/2] [.NET 5] Update TargetFramework to net5.0 The latest .NET 5 previews now have support for a $(TargetFramework) of `net5.0`, which allows us to replace our usage of `netcoreapp5.0` with `net5.0`. The .NET 5 version of `_ResolveSdks` has also been updated to avoid avoid usage of $(TargetFramework) when setting the path to `Mono.Android.dll`. This fixes an issue that was occurring when using the latest .NET 5 nightly preview, which was the result of Android projects using targeting packs with different $(TargetFramework) values. /Users/peter/.nuget/packages/microsoft.android.sdk/10.0.100-ci.net5-fix-tf.22/tools/Xamarin.Android.Tooling.targets(61,5): error XARSD7004: System.ArgumentException: `/usr/local/share/dotnet/packs/Microsoft.NETCore.App.Ref/5.0.0-preview.6.20264.1/ref/netcoreapp5.0` must be a directory! (Parameter 'frameworkDirectories') /Users/peter/.nuget/packages/microsoft.android.sdk/10.0.100-ci.net5-fix-tf.22/tools/Xamarin.Android.Tooling.targets(61,5): error XARSD7004: at Xamarin.Android.Tools.AndroidVersions..ctor(IEnumerable`1 frameworkDirectories) in /Users/peter/source/pj/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/AndroidVersions.cs:line 30 /Users/peter/.nuget/packages/microsoft.android.sdk/10.0.100-ci.net5-fix-tf.22/tools/Xamarin.Android.Tooling.targets(61,5): error XARSD7004: at Xamarin.Android.Tasks.MonoAndroidHelper.RefreshSupportedVersions(String[] referenceAssemblyPaths) /Users/peter/.nuget/packages/microsoft.android.sdk/10.0.100-ci.net5-fix-tf.22/tools/Xamarin.Android.Tooling.targets(61,5): error XARSD7004: at Xamarin.Android.Tasks.ResolveSdks.RunTask() /Users/peter/.nuget/packages/microsoft.android.sdk/10.0.100-ci.net5-fix-tf.22/tools/Xamarin.Android.Tooling.targets(61,5): error XARSD7004: at Xamarin.Android.Tasks.AndroidTask.Execute() --- Documentation/guides/DotNet5.md | 2 +- build-tools/automation/azure-pipelines-oss.yaml | 2 +- build-tools/automation/azure-pipelines.yaml | 2 +- build-tools/create-packs/Microsoft.Android.Ref.proj | 2 +- build-tools/create-packs/Microsoft.Android.Runtime.proj | 2 +- build-tools/create-packs/Microsoft.Android.Sdk.proj | 2 +- .../Tests/Xamarin.ProjectTools/Android/XASdkProject.cs | 7 +++++-- .../Xamarin.Android.Tooling.targets | 9 ++++----- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Documentation/guides/DotNet5.md b/Documentation/guides/DotNet5.md index b6da293e023..2ac7a95015d 100644 --- a/Documentation/guides/DotNet5.md +++ b/Documentation/guides/DotNet5.md @@ -156,7 +156,7 @@ The following instructions can be used for early preview testing. ```xml - netcoreapp5.0 + net5.0 android.21-arm64 Exe diff --git a/build-tools/automation/azure-pipelines-oss.yaml b/build-tools/automation/azure-pipelines-oss.yaml index 40242ceb41e..775a26c053c 100644 --- a/build-tools/automation/azure-pipelines-oss.yaml +++ b/build-tools/automation/azure-pipelines-oss.yaml @@ -27,7 +27,7 @@ variables: PREPARE_FLAGS: PREPARE_CI=1 PREPARE_CI_PR=1 DotNetCoreVersion: 3.1.201 # Version number from: https://dotnet.microsoft.com/download/dotnet-core/5.0 - DotNetCorePreviewVersion: 5.0.100-preview.4.20227.14 + DotNetCorePreviewVersion: 5.0.100-preview.6.20265.2 stages: - stage: mac_stage diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index bfca97576fa..c0bab5b02b5 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -50,7 +50,7 @@ variables: NUnitConsoleVersion: 3.9.0 DotNetCoreVersion: 3.1.201 # Version number from: https://github.com/dotnet/installer#installers-and-binaries - DotNetCorePreviewVersion: 5.0.100-preview.4.20227.14 + DotNetCorePreviewVersion: 5.0.100-preview.6.20265.2 HostedMacMojave: Hosted Mac Internal Mojave HostedMac: Hosted Mac Internal HostedWinVS2019: Hosted Windows 2019 with VS2019 diff --git a/build-tools/create-packs/Microsoft.Android.Ref.proj b/build-tools/create-packs/Microsoft.Android.Ref.proj index c5ec2a4620a..147dd5bd11f 100644 --- a/build-tools/create-packs/Microsoft.Android.Ref.proj +++ b/build-tools/create-packs/Microsoft.Android.Ref.proj @@ -15,7 +15,7 @@ by projects that use the Microsoft.Android framework in .NET 5. Microsoft Microsoft.Android reference assemblies. Please do not reference directly. ..\..\bin\Build$(Configuration)\nupkgs\ - <_AndroidRefPackAssemblyPath>ref\netcoreapp5.0 + <_AndroidRefPackAssemblyPath>ref\net5.0 diff --git a/build-tools/create-packs/Microsoft.Android.Runtime.proj b/build-tools/create-packs/Microsoft.Android.Runtime.proj index f54b94d2d8a..6712bd2137d 100644 --- a/build-tools/create-packs/Microsoft.Android.Runtime.proj +++ b/build-tools/create-packs/Microsoft.Android.Runtime.proj @@ -17,7 +17,7 @@ projects that use the Microsoft.Android framework in .NET 5. Microsoft Microsoft.Android runtime components. Please do not reference directly. ..\..\bin\Build$(Configuration)\nupkgs\ - <_AndroidRuntimePackAssemblyPath>runtimes\$(AndroidRID)\lib\netcoreapp5.0 + <_AndroidRuntimePackAssemblyPath>runtimes\$(AndroidRID)\lib\net5.0 <_AndroidRuntimePackNativePath>runtimes\$(AndroidRID)\native diff --git a/build-tools/create-packs/Microsoft.Android.Sdk.proj b/build-tools/create-packs/Microsoft.Android.Sdk.proj index cbe73660342..d266cdd4ed6 100644 --- a/build-tools/create-packs/Microsoft.Android.Sdk.proj +++ b/build-tools/create-packs/Microsoft.Android.Sdk.proj @@ -85,7 +85,7 @@ the new entry point for short-form style Android projets in .NET 5. - <_AndroidNETAppTargetFramework>netcoreapp5.0 + <_AndroidNETAppTargetFramework>net5.0 Microsoft.Android.Sdk.BundledVersions.props diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XASdkProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XASdkProject.cs index dcd36742a08..369b0ef1171 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XASdkProject.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XASdkProject.cs @@ -39,11 +39,14 @@ static XASdkProject () public XASdkProject (string sdkVersion = "", string outputType = "Exe") { Sdk = string.IsNullOrEmpty (sdkVersion) ? "Microsoft.Android.Sdk" : $"Microsoft.Android.Sdk/{sdkVersion}"; - TargetFramework = "netcoreapp5.0"; + TargetFramework = "net5.0"; PackageName = PackageName ?? string.Format ("{0}.{0}", ProjectName); JavaPackageName = JavaPackageName ?? PackageName.ToLowerInvariant (); - ExtraNuGetConfigSources = new List { Path.Combine (XABuildPaths.BuildOutputDirectory, "nupkgs") }; + ExtraNuGetConfigSources = new List { + Path.Combine (XABuildPaths.BuildOutputDirectory, "nupkgs"), + "https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet5/nuget/v3/index.json", + }; GlobalPackagesFolder = Path.Combine (XABuildPaths.TopDirectory, "packages"); SetProperty (KnownProperties.OutputType, outputType); diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets index fd9eeee08bd..6cf5d926232 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets @@ -43,7 +43,7 @@ projects. - <_ResolveSdksDependsOnTargets>ResolveFrameworkReferences + <_ResolveSdksDependsOnTargets>ResolveTargetingPackAssets <_ResolveSdksDependsOnTargets>_GetReferenceAssemblyPaths @@ -52,11 +52,10 @@ projects. <_AndroidAllowMissingSdkTooling Condition=" '$(_AndroidAllowMissingSdkTooling)' == '' ">False - - <_XATargetFrameworkDirectories Condition=" '$(UsingAndroidNETSdk)' == 'True' ">@(ResolvedFrameworkReference->'%(TargetingPackPath)\ref\$(TargetFramework)') + <_XATargetFrameworkDirectories Condition=" '$(UsingAndroidNETSdk)' == 'True' And '%(FileName)%(Extension)' == 'Mono.Android.dll' ">@(Reference->'%(RootDir)%(Directory)') Date: Mon, 18 May 2020 11:19:48 -0400 Subject: [PATCH 2/2] Use targeting pack metadata to set $(_XATargetFrameworkDirectories) Certain tasks require that $(_XATargetFrameworkDirectories) contains paths to both Mono.Android.dll and mscorlib.dll. In order to ensure that this property contains all known assembly paths we'll use the @(ResolvedTargetingPack) ItemGroup. These items contain metadata definitions for %(TargetFramework) and %(PackagePath), which can be combined to construct the full assembly path for each pack. --- .../Xamarin.Android.Tooling.targets | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets index 6cf5d926232..025063d5fa6 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets @@ -50,12 +50,17 @@ projects. + + + <_ResolveSdksFrameworkRefAssemblyPaths Include="@(ResolvedTargetingPack->'%(Path)\ref\%(TargetFramework)')" Condition=" '@(ResolvedTargetingPack)' == '@(FrameworkReference)' and '%(Identity)' != '' " /> + <_AndroidAllowMissingSdkTooling Condition=" '$(_AndroidAllowMissingSdkTooling)' == '' ">False - - <_XATargetFrameworkDirectories Condition=" '$(UsingAndroidNETSdk)' == 'True' And '%(FileName)%(Extension)' == 'Mono.Android.dll' ">@(Reference->'%(RootDir)%(Directory)') + <_XATargetFrameworkDirectories Condition=" '$(UsingAndroidNETSdk)' == 'True' ">@(_ResolveSdksFrameworkRefAssemblyPaths)