diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 81278881ebd2..245aa9bdf5aa 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -112,6 +112,8 @@ public class ProcessFrameworkReferences : TaskBase [Required] public string NETCoreSdkRuntimeIdentifier { get; set; } + public string NETCoreSdkPortableRuntimeIdentifier { get; set; } + [Required] public string NetCoreRoot { get; set; } @@ -778,9 +780,17 @@ private ToolPackSupport AddToolPack( var packNamePattern = knownPack.GetMetadata(packName + "PackNamePattern"); var packSupportedRuntimeIdentifiers = knownPack.GetMetadata(packName + "RuntimeIdentifiers").Split(';'); + // When publishing for the non-portable RID that matches NETCoreSdkRuntimeIdentifier, prefer NETCoreSdkRuntimeIdentifier for the host. + // Otherwise prefer the NETCoreSdkPortableRuntimeIdentifier. + // This makes non-portable SDKs behave the same as portable SDKs except for the specific case of targetting the non-portable RID. + // It also enables the non-portable ILCompiler to be packaged separately from the SDK and + // only required when publishing for the non-portable SDK RID. + string portableSdkRid = !string.IsNullOrEmpty(NETCoreSdkPortableRuntimeIdentifier) ? NETCoreSdkPortableRuntimeIdentifier : NETCoreSdkRuntimeIdentifier; + bool targetsNonPortableSdkRid = RuntimeIdentifier == NETCoreSdkRuntimeIdentifier && NETCoreSdkRuntimeIdentifier != portableSdkRid; + string hostRuntimeIdentifier = targetsNonPortableSdkRid ? NETCoreSdkRuntimeIdentifier : portableSdkRid; // 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 var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); - var hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, NETCoreSdkRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph); + hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, hostRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph); if (hostRuntimeIdentifier == null) { return ToolPackSupport.UnsupportedForHostRuntimeIdentifier; diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets index a1ce41b29165..6cae30302c06 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets @@ -132,6 +132,7 @@ Copyright (c) .NET Foundation. All rights reserved. KnownWebAssemblySdkPacks="@(KnownWebAssemblySdkPack)" UsingMicrosoftNETSdkWebAssembly="$(UsingMicrosoftNETSdkWebAssembly)" NETCoreSdkRuntimeIdentifier="$(NETCoreSdkRuntimeIdentifier)" + NETCoreSdkPortableRuntimeIdentifier="$(NETCoreSdkPortableRuntimeIdentifier)" NetCoreRoot="$(NetCoreRoot)" NETCoreSdkVersion="$(NETCoreSdkVersion)">