Skip to content

Commit b7b18bf

Browse files
authored
[.NET 5] Update TargetFramework to net5.0 (#4692)
Bumps to .NET 5.0.100-preview.6.20265.2 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. 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') 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 error XARSD7004: at Xamarin.Android.Tasks.MonoAndroidHelper.RefreshSupportedVersions(String[] referenceAssemblyPaths) error XARSD7004: at Xamarin.Android.Tasks.ResolveSdks.RunTask() error XARSD7004: at Xamarin.Android.Tasks.AndroidTask.Execute() * 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.
1 parent 9121224 commit b7b18bf

File tree

8 files changed

+21
-14
lines changed

8 files changed

+21
-14
lines changed

Documentation/guides/DotNet5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ The following instructions can be used for early preview testing.
156156
```xml
157157
<Project Sdk="Microsoft.Android.Sdk/10.0.100">
158158
<PropertyGroup>
159-
<TargetFramework>netcoreapp5.0</TargetFramework>
159+
<TargetFramework>net5.0</TargetFramework>
160160
<RuntimeIdentifier>android.21-arm64</RuntimeIdentifier>
161161
<OutputType>Exe</OutputType>
162162
</PropertyGroup>

build-tools/automation/azure-pipelines-oss.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ variables:
2727
PREPARE_FLAGS: PREPARE_CI=1 PREPARE_CI_PR=1
2828
DotNetCoreVersion: 3.1.201
2929
# Version number from: https://dotnet.microsoft.com/download/dotnet-core/5.0
30-
DotNetCorePreviewVersion: 5.0.100-preview.4.20227.14
30+
DotNetCorePreviewVersion: 5.0.100-preview.6.20265.2
3131

3232
stages:
3333
- stage: mac_stage

build-tools/automation/azure-pipelines.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ variables:
5050
NUnitConsoleVersion: 3.9.0
5151
DotNetCoreVersion: 3.1.201
5252
# Version number from: https://github.com/dotnet/installer#installers-and-binaries
53-
DotNetCorePreviewVersion: 5.0.100-preview.4.20227.14
53+
DotNetCorePreviewVersion: 5.0.100-preview.6.20265.2
5454
HostedMacMojave: Hosted Mac Internal Mojave
5555
HostedMac: Hosted Mac Internal
5656
HostedWinVS2019: Hosted Windows 2019 with VS2019

build-tools/create-packs/Microsoft.Android.Ref.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ by projects that use the Microsoft.Android framework in .NET 5.
1515
<Authors>Microsoft</Authors>
1616
<Description>Microsoft.Android reference assemblies. Please do not reference directly.</Description>
1717
<OutputPath>..\..\bin\Build$(Configuration)\nupkgs\</OutputPath>
18-
<_AndroidRefPackAssemblyPath>ref\netcoreapp5.0</_AndroidRefPackAssemblyPath>
18+
<_AndroidRefPackAssemblyPath>ref\net5.0</_AndroidRefPackAssemblyPath>
1919
</PropertyGroup>
2020

2121
<PropertyGroup>

build-tools/create-packs/Microsoft.Android.Runtime.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ projects that use the Microsoft.Android framework in .NET 5.
1717
<Authors>Microsoft</Authors>
1818
<Description>Microsoft.Android runtime components. Please do not reference directly.</Description>
1919
<OutputPath>..\..\bin\Build$(Configuration)\nupkgs\</OutputPath>
20-
<_AndroidRuntimePackAssemblyPath>runtimes\$(AndroidRID)\lib\netcoreapp5.0</_AndroidRuntimePackAssemblyPath>
20+
<_AndroidRuntimePackAssemblyPath>runtimes\$(AndroidRID)\lib\net5.0</_AndroidRuntimePackAssemblyPath>
2121
<_AndroidRuntimePackNativePath>runtimes\$(AndroidRID)\native</_AndroidRuntimePackNativePath>
2222
</PropertyGroup>
2323

build-tools/create-packs/Microsoft.Android.Sdk.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ the new entry point for short-form style Android projets in .NET 5.
8585
<Target Name="_GenerateBundledVersions"
8686
DependsOnTargets="_GetDefaultPackageVersion" >
8787
<PropertyGroup>
88-
<_AndroidNETAppTargetFramework>netcoreapp5.0</_AndroidNETAppTargetFramework>
88+
<_AndroidNETAppTargetFramework>net5.0</_AndroidNETAppTargetFramework>
8989
<BundledVersionsPropsFileName>Microsoft.Android.Sdk.BundledVersions.props</BundledVersionsPropsFileName>
9090
</PropertyGroup>
9191

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XASdkProject.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ static XASdkProject ()
3939
public XASdkProject (string sdkVersion = "", string outputType = "Exe")
4040
{
4141
Sdk = string.IsNullOrEmpty (sdkVersion) ? "Microsoft.Android.Sdk" : $"Microsoft.Android.Sdk/{sdkVersion}";
42-
TargetFramework = "netcoreapp5.0";
42+
TargetFramework = "net5.0";
4343

4444
PackageName = PackageName ?? string.Format ("{0}.{0}", ProjectName);
4545
JavaPackageName = JavaPackageName ?? PackageName.ToLowerInvariant ();
46-
ExtraNuGetConfigSources = new List<string> { Path.Combine (XABuildPaths.BuildOutputDirectory, "nupkgs") };
46+
ExtraNuGetConfigSources = new List<string> {
47+
Path.Combine (XABuildPaths.BuildOutputDirectory, "nupkgs"),
48+
"https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet5/nuget/v3/index.json",
49+
};
4750
GlobalPackagesFolder = Path.Combine (XABuildPaths.TopDirectory, "packages");
4851
SetProperty (KnownProperties.OutputType, outputType);
4952

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,24 @@ projects.
4343
</Target>
4444

4545
<PropertyGroup Condition=" '$(UsingAndroidNETSdk)' == 'True' ">
46-
<_ResolveSdksDependsOnTargets>ResolveFrameworkReferences</_ResolveSdksDependsOnTargets>
46+
<_ResolveSdksDependsOnTargets>ResolveTargetingPackAssets</_ResolveSdksDependsOnTargets>
4747
</PropertyGroup>
4848
<PropertyGroup Condition=" '$(UsingAndroidNETSdk)' != 'True' ">
4949
<_ResolveSdksDependsOnTargets>_GetReferenceAssemblyPaths</_ResolveSdksDependsOnTargets>
5050
</PropertyGroup>
5151

5252
<Target Name="_ResolveSdks" DependsOnTargets="$(_ResolveSdksDependsOnTargets)">
53+
<!-- When using .NET 5, provide a list of paths to the Android and NETCore targeting pack directories, e.g.
54+
`packages\microsoft.android.ref\10.0.100-ci.master.22\ref\net5.0\` and
55+
`C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\5.0.0-preview.6.20264.1\ref\net5.0\`
56+
See https://github.com/dotnet/sdk/blob/9eeb58e24af894597a534326156d09173d9f0f91/src/Tasks/Microsoft.NET.Build.Tasks/ResolveTargetingPackAssets.cs#L56
57+
-->
58+
<ItemGroup Condition=" '$(UsingAndroidNETSdk)' == 'True' ">
59+
<_ResolveSdksFrameworkRefAssemblyPaths Include="@(ResolvedTargetingPack->'%(Path)\ref\%(TargetFramework)')" Condition=" '@(ResolvedTargetingPack)' == '@(FrameworkReference)' and '%(Identity)' != '' " />
60+
</ItemGroup>
5361
<PropertyGroup>
5462
<_AndroidAllowMissingSdkTooling Condition=" '$(_AndroidAllowMissingSdkTooling)' == '' ">False</_AndroidAllowMissingSdkTooling>
55-
<!-- When using .NET 5, provide a list of paths to all framework reference directories, e.g.
56-
`packages\xamarin.android.app.ref\10.3.99.160\ref\netcoreapp5.0\` and
57-
`C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\5.0.0-preview.2.20160.6\ref\netcoreapp5.0\`
58-
-->
59-
<_XATargetFrameworkDirectories Condition=" '$(UsingAndroidNETSdk)' == 'True' ">@(ResolvedFrameworkReference->'%(TargetingPackPath)\ref\$(TargetFramework)')</_XATargetFrameworkDirectories>
63+
<_XATargetFrameworkDirectories Condition=" '$(UsingAndroidNETSdk)' == 'True' ">@(_ResolveSdksFrameworkRefAssemblyPaths)</_XATargetFrameworkDirectories>
6064
</PropertyGroup>
6165
<ResolveSdks
6266
ContinueOnError="$(_AndroidAllowMissingSdkTooling)"

0 commit comments

Comments
 (0)