From 8dcb48edbe2fa88c0b68322840436ae6e5f48d88 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 26 Jun 2023 11:07:59 -0700 Subject: [PATCH] Make non-portable RID warning check all available NETCore.App RIDS for the current TFM --- .../ProcessFrameworkReferences.cs | 22 +++++++++++-------- .../GivenThatWeWantToBuildANetCoreApp.cs | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index f61a393b3931..109c65a6618f 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -166,7 +166,6 @@ protected override void ExecuteCore() List runtimePacks = new List(); List unavailableRuntimePacks = new List(); - HashSet knownRuntimeIdentifierPlatforms = new HashSet(StringComparer.OrdinalIgnoreCase); HashSet unrecognizedRuntimeIdentifiers = new HashSet(StringComparer.OrdinalIgnoreCase); bool windowsOnlyErrorLogged = false; @@ -207,14 +206,6 @@ protected override void ExecuteCore() string runtimePackName = runtimePackNamePattern.Replace("**RID**", runtimeIdentifier); preferredPackages.Add(runtimePackName); } - - // Update the known runtime identifier platforms based on the selected Microsoft.NETCore.App pack - if (selectedRuntimePack.Value.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)) - { - int separator = runtimeIdentifier.LastIndexOf('-'); - string platform = separator < 0 ? runtimeIdentifier : runtimeIdentifier.Substring(0, separator); - knownRuntimeIdentifierPlatforms.Add(platform); - } } } @@ -451,6 +442,19 @@ var runtimeRequiredByDeployment ImplicitPackageReferences = implicitPackageReferences.ToArray(); } + // Determine the known runtime identifier platforms based on all available Microsoft.NETCore.App packs + HashSet knownRuntimeIdentifierPlatforms = new HashSet(StringComparer.OrdinalIgnoreCase); + var netCoreAppPacks = knownRuntimePacksForTargetFramework.Where(krp => krp.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)); + foreach (KnownRuntimePack netCoreAppPack in netCoreAppPacks) + { + foreach (var runtimeIdentifier in netCoreAppPack.RuntimePackRuntimeIdentifiers.Split(';')) + { + int separator = runtimeIdentifier.LastIndexOf('-'); + string platform = separator < 0 ? runtimeIdentifier : runtimeIdentifier.Substring(0, separator); + knownRuntimeIdentifierPlatforms.Add(platform); + } + } + if (knownRuntimeIdentifierPlatforms.Count > 0) { KnownRuntimeIdentifierPlatforms = knownRuntimeIdentifierPlatforms.ToArray(); diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs index 162d982938c4..2f6d197eca6f 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs @@ -935,7 +935,7 @@ public void It_builds_the_project_successfully_with_only_reference_assembly_set( // Non-portable and portable RIDs should warn [InlineData(ToolsetInfo.CurrentTargetFramework, new[] { "ubuntu.22.04-x64", "win7-x86", "unix" }, true, true, null, true)] // Portable RIDs only should not warn - [InlineData(ToolsetInfo.CurrentTargetFramework, new[] { "win-x86", "linux", "linux-musl-x64", "osx-arm64", "unix" }, true, true, null, false)] + [InlineData(ToolsetInfo.CurrentTargetFramework, new[] { "win-x86", "win", "linux", "linux-musl-x64", "osx", "osx-arm64", "unix", "browser", "browser-wasm", "ios-arm64" }, true, true, null, false)] // No RID assets should not warn [InlineData(ToolsetInfo.CurrentTargetFramework, new string[] { }, false, false, null, false)] // Below .NET 8 should not warn