diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets
index 9ec28273a23..12d881cc44a 100644
--- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets
+++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets
@@ -40,7 +40,6 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android.
<_AndroidNetCoreAppNativeAotKnownRuntimePack Include="@(KnownRuntimePack->WithMetadataValue('Identity', 'Microsoft.NETCore.App')->WithMetadataValue('RuntimePackLabels', 'NativeAOT'))" />
- $(MicrosoftNETCoreAppRefPackageVersion)
%(RuntimePackRuntimeIdentifiers);android-arm
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/NativeAotBuildTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/NativeAotBuildTests.cs
index 9f1cfab9198..37e7dd72c8e 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/NativeAotBuildTests.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/NativeAotBuildTests.cs
@@ -1,4 +1,5 @@
using System.IO;
+using System.Text.RegularExpressions;
using NUnit.Framework;
using Xamarin.Android.Tasks;
@@ -42,6 +43,38 @@ public void RestoreNativeAot_AndroidArmRuntimePack ()
);
}
+ [Test]
+ public void RestoreNativeAot_UsesSdkRuntimePackVersion ()
+ {
+ var proj = new XamarinAndroidApplicationProject {
+ IsRelease = true,
+ };
+ proj.SetRuntime (AndroidRuntime.NativeAOT);
+
+ using var builder = CreateApkBuilder ();
+ Assert.IsTrue (
+ builder.RunTarget (proj, "Restore", parameters: [
+ "MicrosoftNETCoreAppRefPackageVersion=0.0.0",
+ ]),
+ "Restore should use the .NET SDK's NativeAOT runtime pack version."
+ );
+
+ var intermediate = Path.Combine (Root, builder.ProjectDirectory, proj.IntermediateOutputPath);
+ var assets = File.ReadAllText (Path.Combine (intermediate, "..", "project.assets.json"));
+
+ // Library entries in project.assets.json are keyed as "PackageId/Version".
+ var runtimePackMatch = Regex.Match (assets, "\"Microsoft\\.NETCore\\.App\\.Runtime\\.NativeAOT\\.[a-z0-9.-]+/([^\"]+)\"");
+ Assert.IsTrue (
+ runtimePackMatch.Success,
+ "Restore should select a NativeAOT runtime pack."
+ );
+ Assert.AreNotEqual (
+ "0.0.0",
+ runtimePackMatch.Groups [1].Value,
+ "Restore should ignore the invalid MicrosoftNETCoreAppRefPackageVersion and use the SDK-selected NativeAOT runtime pack version."
+ );
+ }
+
[Test]
public void BuildNativeAot_WithoutNdk ()
{