Skip to content

Commit e6f8a39

Browse files
authored
Allow opting-in to NativeAOT publishing using runtime packs (#32100)
1 parent ed8a052 commit e6f8a39

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class ProcessFrameworkReferences : TaskBase
4848

4949
public bool AotEnabled { get; set; }
5050

51+
public bool AotUseKnownRuntimePackForTarget { get; set; }
52+
5153
public string RuntimeIdentifier { get; set; }
5254

5355
public string[] RuntimeIdentifiers { get; set; }
@@ -678,9 +680,10 @@ private bool AddToolPack(
678680
case ToolPackType.ILCompiler:
679681
HostILCompilerPacks = new[] { runtimePackItem };
680682

681-
// ILCompiler supports cross target compilation. If there is a cross-target request, we need to download that package as well
683+
// ILCompiler supports cross target compilation. If there is a cross-target request,
684+
// we need to download that package as well unless we use KnownRuntimePack entries for the target.
682685
// We expect RuntimeIdentifier to be defined during publish but can allow during build
683-
if (RuntimeIdentifier != null)
686+
if (RuntimeIdentifier != null && !AotUseKnownRuntimePackForTarget)
684687
{
685688
var targetRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, RuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph2);
686689
if (targetRuntimeIdentifier == null)

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ Copyright (c) .NET Foundation. All rights reserved.
8989
RuntimePackLabels="Mono"
9090
Condition="'$(UseMonoRuntime)' == 'true' And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '6.0')" />
9191

92+
<!-- Allow opt-in to NativeAOT runtime pack for .NET 8.0 or higher -->
93+
<FrameworkReference Update="Microsoft.NETCore.App"
94+
RuntimePackLabels="NativeAOT"
95+
Condition="'$(PublishAotUsingRuntimePack)' == 'true' And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '8.0')" />
96+
9297
</ItemGroup>
9398

9499
</Project>

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Copyright (c) .NET Foundation. All rights reserved.
101101
ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
102102
TrimmingEnabled="$(_IsTrimmingEnabled)"
103103
AotEnabled="$(PublishAot)"
104+
AotUseKnownRuntimePackForTarget="$(PublishAotUsingRuntimePack)"
104105
RuntimeIdentifier="$(RuntimeIdentifier)"
105106
RuntimeIdentifiers="$(RuntimeIdentifiers)"
106107
RuntimeFrameworkVersion="$(RuntimeFrameworkVersion)"

0 commit comments

Comments
 (0)