From 3d4a491a1d8eeaf067d9149c3fcad9d280ca28f2 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Mon, 24 Jun 2024 11:46:07 +0200 Subject: [PATCH 1/4] Prefer the portable ILCompiler when publishing for the portable RID on a source-built SDK. --- .../ProcessFrameworkReferences.cs | 16 +++++++++++++++- ....NET.Sdk.FrameworkReferenceResolution.targets | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 81278881ebd2..5585bf7085d6 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; } @@ -780,7 +782,19 @@ private ToolPackSupport AddToolPack( // 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); + string hostRuntimeIdentifier = null; + // When a non-portable SDK publishes for its non-portable RID specifically, prefer a non-portable host package. + string portableSdkRid = !string.IsNullOrEmpty(NETCoreSdkPortableRuntimeIdentifier) ? NETCoreSdkPortableRuntimeIdentifier : RuntimeIdentifier; + bool isNonPortablePublish = RuntimeIdentifier == NETCoreSdkRuntimeIdentifier && NETCoreSdkRuntimeIdentifier != portableSdkRid; + if (isNonPortablePublish) + { + hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, NETCoreSdkRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph); + } + // Otherwise, non-portable SDKs behave the same as portable SDKs. + if (hostRuntimeIdentifier == null) + { + hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, portableSdkRid, 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)"> From 08c7beb0fa106437b5a3e6ca1f0e5e075d30410f Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Wed, 26 Jun 2024 09:35:03 +0200 Subject: [PATCH 2/4] Refactor/simplify. --- .../ProcessFrameworkReferences.cs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 5585bf7085d6..2ed40f22ef38 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -782,19 +782,11 @@ private ToolPackSupport AddToolPack( // 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); - string hostRuntimeIdentifier = null; - // When a non-portable SDK publishes for its non-portable RID specifically, prefer a non-portable host package. - string portableSdkRid = !string.IsNullOrEmpty(NETCoreSdkPortableRuntimeIdentifier) ? NETCoreSdkPortableRuntimeIdentifier : RuntimeIdentifier; - bool isNonPortablePublish = RuntimeIdentifier == NETCoreSdkRuntimeIdentifier && NETCoreSdkRuntimeIdentifier != portableSdkRid; - if (isNonPortablePublish) - { - hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, NETCoreSdkRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph); - } - // Otherwise, non-portable SDKs behave the same as portable SDKs. - if (hostRuntimeIdentifier == null) - { - hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, portableSdkRid, packSupportedRuntimeIdentifiers, out bool wasInGraph); - } + // When publishing for the RuntimeIdentifier that matches NETCoreSdkPortableRuntimeIdentifier, prefer NETCoreSdkPortableRuntimeIdentifier for the host. + // This makes us use a portable ILCompiler when publishing for a portable RID on a non-portable SDK. + string hostRuntimeIdentifier = RuntimeIdentifier == NETCoreSdkPortableRuntimeIdentifier ? NETCoreSdkPortableRuntimeIdentifier : NETCoreSdkRuntimeIdentifier; + // Find the best ILCompiler for hostRuntimeIdentifier. + hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, hostRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph); if (hostRuntimeIdentifier == null) { return ToolPackSupport.UnsupportedForHostRuntimeIdentifier; From d38d1e3941629e86410f77f013ec9e227f0e58e9 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Wed, 26 Jun 2024 09:37:11 +0200 Subject: [PATCH 3/4] Move code. --- .../Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 2ed40f22ef38..aad708ef6f45 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -780,12 +780,11 @@ private ToolPackSupport AddToolPack( var packNamePattern = knownPack.GetMetadata(packName + "PackNamePattern"); var packSupportedRuntimeIdentifiers = knownPack.GetMetadata(packName + "RuntimeIdentifiers").Split(';'); - // 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); // When publishing for the RuntimeIdentifier that matches NETCoreSdkPortableRuntimeIdentifier, prefer NETCoreSdkPortableRuntimeIdentifier for the host. // This makes us use a portable ILCompiler when publishing for a portable RID on a non-portable SDK. string hostRuntimeIdentifier = RuntimeIdentifier == NETCoreSdkPortableRuntimeIdentifier ? NETCoreSdkPortableRuntimeIdentifier : NETCoreSdkRuntimeIdentifier; - // Find the best ILCompiler for hostRuntimeIdentifier. + // 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); hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, hostRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph); if (hostRuntimeIdentifier == null) { From 0132c131704cf787c9f4c82d5499c6690073c48c Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Wed, 26 Jun 2024 12:18:10 +0200 Subject: [PATCH 4/4] Fix when publishing for other portable rids. --- .../ProcessFrameworkReferences.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index aad708ef6f45..245aa9bdf5aa 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -780,9 +780,14 @@ private ToolPackSupport AddToolPack( var packNamePattern = knownPack.GetMetadata(packName + "PackNamePattern"); var packSupportedRuntimeIdentifiers = knownPack.GetMetadata(packName + "RuntimeIdentifiers").Split(';'); - // When publishing for the RuntimeIdentifier that matches NETCoreSdkPortableRuntimeIdentifier, prefer NETCoreSdkPortableRuntimeIdentifier for the host. - // This makes us use a portable ILCompiler when publishing for a portable RID on a non-portable SDK. - string hostRuntimeIdentifier = RuntimeIdentifier == NETCoreSdkPortableRuntimeIdentifier ? NETCoreSdkPortableRuntimeIdentifier : NETCoreSdkRuntimeIdentifier; + // 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); hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, hostRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph);