Skip to content

Commit

Permalink
Fix runtime pack handling of profiles combined with no profiles
Browse files Browse the repository at this point in the history
Fixes #43461
  • Loading branch information
dsplaisted authored and marcpopMSFT committed Oct 3, 2024
1 parent 1ee5f6d commit d1a8098
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITaskItem> 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<string> frameworkReferenceNames = new(FrameworkReferences.Select(item => item.ItemSpec), StringComparer.OrdinalIgnoreCase);
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit d1a8098

Please sign in to comment.