Skip to content

Conversation

dsplaisted
Copy link
Member

Fixes #49248

  • Special-cases xunit.core library so it will never be trimmed from deps.json file
  • Adds new property, TrimDepsJsonLibrariesWithoutAssets, which can be set to false to disable deps.json library trimming

@Copilot Copilot AI review requested due to automatic review settings June 8, 2025 14:43
@dsplaisted dsplaisted requested review from a team as code owners June 8, 2025 14:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #49248 by fixing the trimming behavior of the deps.json file so that the xunit.core library is never trimmed and by adding an opt-out property for deps.json library trimming.

  • Updated tests to verify both trimmed and untrimmed behavior of libraries without assets.
  • Modified various MSBuild targets to pass through the new TrimDepsJsonLibrariesWithoutAssets property.
  • Extended the dependency context builder to conditionally skip trimming of specified libraries.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopLibrary.cs Updated test to use Theory for both trimming enabled/disabled scenarios and added regression test for xunit.core.
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets Added default property for TrimDepsJsonLibrariesWithoutAssets and passed it to the build process.
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets Passed TrimDepsJsonLibrariesWithoutAssets to the publish process.
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.DesignerSupport.targets Ensured TrimDepsJsonLibrariesWithoutAssets is passed in designer support targets.
src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs Introduced a new property and chained it into the dependency context builder.
src/Tasks/Microsoft.NET.Build.Tasks/DependencyContextBuilder.cs Added handling for the new TrimDepsJsonLibrariesWithoutAssets flag with a special case for xunit.core.
Comments suppressed due to low confidence (1)

src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs:235

  • [nitpick] Consider adding a summary comment for the TrimDepsJsonLibrariesWithoutAssets property to clarify its purpose in controlling library trimming behavior.
.WithTrimLibrariesWithoutAssets(TrimDepsJsonLibrariesWithoutAssets)

{
var testProject = new TestProject()
{
TargetFrameworks = ToolsetInfo.CurrentTargetFramework
};
testProject.PackageReferences.Add(new TestPackageReference("Nerdbank.GitVersioning", "3.6.146"));

if (!trimLibrariesWithoutAssets)
{
testProject.AdditionalProperties["TrimDepsJsonLibrariesWithoutAssets"] = "False";
Copy link
Preview

Copilot AI Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using consistent lowercase boolean string representations (e.g., 'false' instead of 'False') to match the casing used in the MSBuild targets.

Suggested change
testProject.AdditionalProperties["TrimDepsJsonLibrariesWithoutAssets"] = "False";
testProject.AdditionalProperties["TrimDepsJsonLibrariesWithoutAssets"] = "false";

Copilot uses AI. Check for mistakes.

var lib = unprocessedLibraries.First();
unprocessedLibraries.Remove(lib);

if (lib.Library.Name.Equals("xunit.core", StringComparison.OrdinalIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check "xunit" as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I've fixed this.

@dsplaisted dsplaisted merged commit 746f86e into dotnet:main Jun 9, 2025
23 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xUnit tests may not be discovered now that the .NET SDK trims packages from deps.json when they don't have any assets
3 participants