Skip to content

Select the NativeAOT runtime pack as the target package when it's provided as part of the KnownILCompilerPack metadata #46611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions src/Layout/redist/targets/GenerateBundledVersions.targets
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<KnownILCompilerPack Include="Microsoft.DotNet.ILCompiler"
TargetFramework="net10.0"
ILCompilerPackNamePattern="runtime.**RID**.Microsoft.DotNet.ILCompiler"
ILCompilerRuntimePackNamePattern="Microsoft.NETCore.App.Runtime.NativeAOT.**RID**"
ILCompilerPackVersion="$(MicrosoftNETCoreAppRuntimePackageVersion)"
ILCompilerRuntimeIdentifiers="@(ILCompilerSupportedRids, '%3B')"
/>
Expand Down
27 changes: 25 additions & 2 deletions src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,36 @@ private ToolPackSupport AddToolPack(
{
return ToolPackSupport.UnsupportedForTargetRuntimeIdentifier;
}
if (!hostRuntimeIdentifier.Equals(targetRuntimeIdentifier))

// If there's an available runtime pack, use it instead of the ILCompiler package for target-specific bits.
bool useRuntimePackForAllTargets = false;
string targetPackNamePattern = packNamePattern;
if (knownPack.GetMetadata("ILCompilerRuntimePackNamePattern") is string runtimePackNamePattern && runtimePackNamePattern != string.Empty)
{
var targetIlcPackName = packNamePattern.Replace("**RID**", targetRuntimeIdentifier);
targetPackNamePattern = runtimePackNamePattern;
useRuntimePackForAllTargets = true;
}

if (useRuntimePackForAllTargets || !hostRuntimeIdentifier.Equals(targetRuntimeIdentifier))
{
var targetIlcPackName = targetPackNamePattern.Replace("**RID**", targetRuntimeIdentifier);
var targetIlcPack = new TaskItem(targetIlcPackName);
targetIlcPack.SetMetadata(MetadataKeys.NuGetPackageId, targetIlcPackName);
targetIlcPack.SetMetadata(MetadataKeys.NuGetPackageVersion, packVersion);
TargetILCompilerPacks = new[] { targetIlcPack };

string targetILCompilerPackPath = GetPackPath(targetIlcPackName, packVersion);
if (targetILCompilerPackPath != null)
{
targetIlcPack.SetMetadata(MetadataKeys.PackageDirectory, targetILCompilerPackPath);
}
else if (EnableRuntimePackDownload)
{
// We need to download the runtime pack
var targetIlcPackToDownload = new TaskItem(targetIlcPackName);
targetIlcPackToDownload.SetMetadata(MetadataKeys.Version, packVersion);
packagesToDownload.Add(targetIlcPackToDownload);
}
}
}

Expand Down
Loading