From d1a80988e42ad9c9b937e434f2d862036a340b28 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Tue, 17 Sep 2024 22:36:25 -0400 Subject: [PATCH] Fix runtime pack handling of profiles combined with no profiles Fixes https://github.com/dotnet/sdk/issues/43461 --- .../ResolveRuntimePackAssets.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs index 8b356984db81..82bd3af81998 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs @@ -31,14 +31,13 @@ protected override void ExecuteCore() // Find any RuntimeFrameworks that matches with FrameworkReferences, so that we can apply that RuntimeFrameworks profile to the corresponding RuntimePack. // This is done in 2 parts, First part (see comments for 2nd part further below), we match the RuntimeFramework with the FrameworkReference by using the following metadata. - // RuntimeFrameworks.GetMetadata("FrameworkName")==FrameworkReferences.ItemSpec AND RuntimeFrameworks.GetMetadata("Profile") is not empty + // RuntimeFrameworks.GetMetadata("FrameworkName")==FrameworkReferences.ItemSpec // For example, A WinForms app that uses useWindowsForms (and useWPF will be set to false) has the following values that will result in a match of the below RuntimeFramework. // FrameworkReferences with an ItemSpec "Microsoft.WindowsDesktop.App.WindowsForms" will match with // RuntimeFramework with an ItemSpec => "Microsoft.WindowsDesktop.App", GetMetadata("FrameworkName") => "Microsoft.WindowsDesktop.App.WindowsForms", GetMetadata("Profile") => "WindowsForms" List matchingRuntimeFrameworks = RuntimeFrameworks != null ? FrameworkReferences .SelectMany(fxReference => RuntimeFrameworks.Where(rtFx => - fxReference.ItemSpec.Equals(rtFx.GetMetadata(MetadataKeys.FrameworkName), StringComparison.OrdinalIgnoreCase) && - !string.IsNullOrEmpty(rtFx.GetMetadata("Profile")))) + fxReference.ItemSpec.Equals(rtFx.GetMetadata(MetadataKeys.FrameworkName), StringComparison.OrdinalIgnoreCase))) .ToList() : null; HashSet frameworkReferenceNames = new(FrameworkReferences.Select(item => item.ItemSpec), StringComparer.OrdinalIgnoreCase); @@ -93,6 +92,13 @@ protected override void ExecuteCore() } } + // If we have a runtime framework with an empty profile, it means that we should use all of the contents of the runtime pack, + // so we can clear the profile list + if (profiles.Contains(string.Empty)) + { + profiles.Clear(); + } + string runtimePackRoot = runtimePack.GetMetadata(MetadataKeys.PackageDirectory); if (string.IsNullOrEmpty(runtimePackRoot) || !Directory.Exists(runtimePackRoot))