Skip to content

Commit 381b445

Browse files
[NativeAOT] Let the SDK select runtime packs (#12750)
The Android RC1 workload stamped its build-time `MicrosoftNETCoreAppRefPackageVersion` into customer projects and used it to rewrite the .NET SDK's NativeAOT `KnownRuntimePack` metadata. When the workload was built against `11.0.0-rc.1.26428.117` but installed with the `11.0.100-rc.1.26425.128` SDK, `dotnet publish -p:PublishAot=true` requested runtime-pack versions that were not available on NuGet.org. - Remove the Android-side `KnownRuntimePack` rewrite now that the .NET SDK advertises `android-arm` itself. - Stop exporting `MicrosoftNETCoreAppRefPackageVersion` from the Android workload's bundled-version targets. - Add restore coverage proving an invalid workload dependency version cannot affect the SDK-selected NativeAOT runtime-pack version. This keeps runtime-pack and ILCompiler selection owned by the installed .NET SDK and avoids mismatches between independently built SDK and Android workload releases. Fixes #12362
1 parent 9c3fc3d commit 381b445

4 files changed

Lines changed: 39 additions & 13 deletions

File tree

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/in/Microsoft.Android.Sdk.BundledVersions.in.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
1010
<PropertyGroup>
1111
<AndroidNETSdkVersion>@ANDROID_PACK_VERSION_LONG@</AndroidNETSdkVersion>
1212
<XamarinAndroidVersion>@ANDROID_PACK_VERSION_LONG@</XamarinAndroidVersion>
13-
<MicrosoftNETCoreAppRefPackageVersion>@MICROSOFT_NETCORE_APP_REF_PACKAGE_VERSION@</MicrosoftNETCoreAppRefPackageVersion>
1413
<_AndroidLatestStableApiLevel>@ANDROID_LATEST_STABLE_API_LEVEL@</_AndroidLatestStableApiLevel>
1514
<_AndroidLatestUnstableApiLevel>@ANDROID_LATEST_UNSTABLE_API_LEVEL@</_AndroidLatestUnstableApiLevel>
1615
<_AndroidSupportedApiLevels>,@ANDROID_API_LEVELS@,</_AndroidSupportedApiLevels>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android.
3434
<IlcExportUnmanagedEntrypoints>true</IlcExportUnmanagedEntrypoints>
3535
</PropertyGroup>
3636

37-
<!-- Outer restores use RuntimeIdentifiers; RuntimeIdentifier is only set in per-RID inner builds. -->
38-
<ItemGroup>
39-
<_AndroidNetCoreAppNativeAotKnownRuntimePack Include="@(KnownRuntimePack->WithMetadataValue('Identity', 'Microsoft.NETCore.App')->WithMetadataValue('RuntimePackLabels', 'NativeAOT'))" />
40-
<KnownRuntimePack Remove="@(_AndroidNetCoreAppNativeAotKnownRuntimePack)" />
41-
<KnownRuntimePack Include="@(_AndroidNetCoreAppNativeAotKnownRuntimePack)">
42-
<LatestRuntimeFrameworkVersion>$(MicrosoftNETCoreAppRefPackageVersion)</LatestRuntimeFrameworkVersion>
43-
<RuntimePackRuntimeIdentifiers>%(RuntimePackRuntimeIdentifiers);android-arm</RuntimePackRuntimeIdentifiers>
44-
</KnownRuntimePack>
45-
</ItemGroup>
46-
4737
<!-- Default property values for NativeAOT Debug configuration -->
4838
<PropertyGroup Condition="'$(DebugSymbols)' == 'true'">
4939
<NativeDebugSymbols>true</NativeDebugSymbols>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/NativeAotBuildTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Linq;
4+
using System.Text.Json;
45

56
using NUnit.Framework;
67
using Xamarin.Android.Tasks;
@@ -101,6 +102,44 @@ public void RestoreNativeAot_AndroidArmRuntimePack ()
101102
);
102103
}
103104

105+
[Test]
106+
public void RestoreNativeAot_UsesSdkRuntimePackVersion ()
107+
{
108+
var proj = new XamarinAndroidApplicationProject {
109+
IsRelease = true,
110+
};
111+
proj.SetRuntime (AndroidRuntime.NativeAOT);
112+
113+
using var builder = CreateApkBuilder ();
114+
Assert.IsTrue (
115+
builder.RunTarget (proj, "Restore", parameters: [
116+
"MicrosoftNETCoreAppRefPackageVersion=0.0.0",
117+
]),
118+
"Restore should use the .NET SDK's NativeAOT runtime pack version."
119+
);
120+
121+
var intermediate = Path.Combine (Root, builder.ProjectDirectory, proj.IntermediateOutputPath);
122+
using var assets = JsonDocument.Parse (File.ReadAllText (Path.Combine (intermediate, "..", "project.assets.json")));
123+
var runtimePacks = assets.RootElement
124+
.GetProperty ("project")
125+
.GetProperty ("frameworks")
126+
.EnumerateObject ()
127+
.SelectMany (framework => framework.Value.GetProperty ("downloadDependencies").EnumerateArray ())
128+
.Where (dependency => dependency.GetProperty ("name").GetString ()?.StartsWith ("Microsoft.NETCore.App.Runtime.NativeAOT.", StringComparison.Ordinal) == true)
129+
.ToArray ();
130+
Assert.IsNotEmpty (
131+
runtimePacks,
132+
"Restore should select a NativeAOT runtime pack."
133+
);
134+
foreach (var runtimePack in runtimePacks) {
135+
Assert.AreNotEqual (
136+
"[0.0.0, 0.0.0]",
137+
runtimePack.GetProperty ("version").GetString (),
138+
"Restore should ignore MicrosoftNETCoreAppRefPackageVersion and use the SDK-selected NativeAOT runtime pack version."
139+
);
140+
}
141+
}
142+
104143
[Test]
105144
public void BuildNativeAot_WithoutNdk ()
106145
{

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@
281281
<_BundledVersionsCacheLines Include="AndroidBuildApiLevel=$(_AndroidBuildApiLevels)" />
282282
<_BundledVersionsCacheLines Include="DotNetTargetFramework=$(DotNetTargetFramework)" />
283283
<_BundledVersionsCacheLines Include="DotNetTargetFrameworkVersion=$(DotNetTargetFrameworkVersion)" />
284-
<_BundledVersionsCacheLines Include="MicrosoftNETCoreAppRefPackageVersion=$(MicrosoftNETCoreAppRefPackageVersion)" />
285284
</ItemGroup>
286285
<WriteLinesToFile
287286
File="$(IntermediateOutputPath)_GenerateBundledVersions.cache"
@@ -304,7 +303,6 @@
304303
<_BundledVersionsReplacement Include="@ANDROID_LATEST_UNSTABLE_API_LEVEL@=$(AndroidLatestUnstableApiLevel)" />
305304
<_BundledVersionsReplacement Include="@ANDROID_API_LEVELS@=$(_AndroidBuildApiLevels)" />
306305
<_BundledVersionsReplacement Include="@DOTNET_TARGET_FRAMEWORK@=$(DotNetTargetFramework)" />
307-
<_BundledVersionsReplacement Include="@MICROSOFT_NETCORE_APP_REF_PACKAGE_VERSION@=$(MicrosoftNETCoreAppRefPackageVersion)" />
308306
</ItemGroup>
309307
<ReplaceFileContents
310308
SourceFile="$(MSBuildThisFileDirectory)Microsoft.Android.Sdk\in\Microsoft.Android.Sdk.BundledVersions.in.targets"

0 commit comments

Comments
 (0)