Skip to content

Commit e18cfb7

Browse files
authored
Prefer the portable ILCompiler when publishing for the portable RID on a source-built SDK. (#41754)
1 parent 437db19 commit e18cfb7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public class ProcessFrameworkReferences : TaskBase
112112
[Required]
113113
public string NETCoreSdkRuntimeIdentifier { get; set; }
114114

115+
public string NETCoreSdkPortableRuntimeIdentifier { get; set; }
116+
115117
[Required]
116118
public string NetCoreRoot { get; set; }
117119

@@ -778,9 +780,17 @@ private ToolPackSupport AddToolPack(
778780
var packNamePattern = knownPack.GetMetadata(packName + "PackNamePattern");
779781
var packSupportedRuntimeIdentifiers = knownPack.GetMetadata(packName + "RuntimeIdentifiers").Split(';');
780782

783+
// When publishing for the non-portable RID that matches NETCoreSdkRuntimeIdentifier, prefer NETCoreSdkRuntimeIdentifier for the host.
784+
// Otherwise prefer the NETCoreSdkPortableRuntimeIdentifier.
785+
// This makes non-portable SDKs behave the same as portable SDKs except for the specific case of targetting the non-portable RID.
786+
// It also enables the non-portable ILCompiler to be packaged separately from the SDK and
787+
// only required when publishing for the non-portable SDK RID.
788+
string portableSdkRid = !string.IsNullOrEmpty(NETCoreSdkPortableRuntimeIdentifier) ? NETCoreSdkPortableRuntimeIdentifier : NETCoreSdkRuntimeIdentifier;
789+
bool targetsNonPortableSdkRid = RuntimeIdentifier == NETCoreSdkRuntimeIdentifier && NETCoreSdkRuntimeIdentifier != portableSdkRid;
790+
string hostRuntimeIdentifier = targetsNonPortableSdkRid ? NETCoreSdkRuntimeIdentifier : portableSdkRid;
781791
// Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture
782792
var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
783-
var hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, NETCoreSdkRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph);
793+
hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, hostRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph);
784794
if (hostRuntimeIdentifier == null)
785795
{
786796
return ToolPackSupport.UnsupportedForHostRuntimeIdentifier;

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
@@ -132,6 +132,7 @@ Copyright (c) .NET Foundation. All rights reserved.
132132
KnownWebAssemblySdkPacks="@(KnownWebAssemblySdkPack)"
133133
UsingMicrosoftNETSdkWebAssembly="$(UsingMicrosoftNETSdkWebAssembly)"
134134
NETCoreSdkRuntimeIdentifier="$(NETCoreSdkRuntimeIdentifier)"
135+
NETCoreSdkPortableRuntimeIdentifier="$(NETCoreSdkPortableRuntimeIdentifier)"
135136
NetCoreRoot="$(NetCoreRoot)"
136137
NETCoreSdkVersion="$(NETCoreSdkVersion)">
137138

0 commit comments

Comments
 (0)