Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/9.0.1xx] Fix SelfContained build/publish when FrameworkReference with profile is combined with FrameworkReference without profile #43555

Open
wants to merge 2 commits into
base: release/9.0.1xx
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,33 @@ public void ItBuildsWhenReferencingWindowsUIXamlTypesWithUseUwpProperty()
.Pass();
}

[WindowsOnlyFact]
public void ItHandlesProfilesWithSelfContained()
{
TestProject testProject = new()
{
TargetFrameworks = $"{ToolsetInfo.CurrentTargetFramework}-windows",
IsExe = true,
SelfContained = "true",
RuntimeIdentifier = "win-x64"
};
// Setting both UseWpf and UseWindowsForms to true will add a FrameworkReference to Microsoft.WindowsDesktop.App
testProject.AdditionalProperties["UseWpf"] = "true";
testProject.AdditionalProperties["UseWindowsForms"] = "true";

// Add reference to Windows Forms, which is a profile of Microsoft.WindowsDesktop.App
testProject.AddItem("FrameworkReference", "Include", "Microsoft.WindowsDesktop.App.WindowsForms");

var testAsset = _testAssetsManager.CreateTestProject(testProject);

var buildCommand = new BuildCommand(testAsset);
buildCommand.Execute().Should().Pass();

// PresentationFramework should be included in output, even though it's not in the WindowsForms profile,
// it should be included because of the Microsoft.WindowsDesktop.App FrameworkReference
buildCommand.GetOutputDirectory().Should().HaveFile("PresentationFramework.dll");
}

private string GetReferencedWindowsSdkVersion(TestAsset testAsset)
{
var getValueCommand = new GetValuesCommand(testAsset, "PackageDownload", GetValuesCommand.ValueType.Item)
Expand Down
Loading