Fix deps.json trimming with xUnit v2 and allow opt-out#49295
Merged
dsplaisted merged 3 commits intodotnet:mainfrom Jun 9, 2025
Merged
Fix deps.json trimming with xUnit v2 and allow opt-out#49295dsplaisted merged 3 commits intodotnet:mainfrom
dsplaisted merged 3 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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)
|
|
||
| if (!trimLibrariesWithoutAssets) | ||
| { | ||
| testProject.AdditionalProperties["TrimDepsJsonLibrariesWithoutAssets"] = "False"; |
There was a problem hiding this comment.
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"; |
This was referenced Jun 8, 2025
Youssef1313
reviewed
Jun 8, 2025
| var lib = unprocessedLibraries.First(); | ||
| unprocessedLibraries.Remove(lib); | ||
|
|
||
| if (lib.Library.Name.Equals("xunit.core", StringComparison.OrdinalIgnoreCase)) |
Member
There was a problem hiding this comment.
Should this check "xunit" as well?
Member
Author
There was a problem hiding this comment.
Good point, I've fixed this.
baronfel
approved these changes
Jun 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #49248
xunit.corelibrary so it will never be trimmed from deps.json fileTrimDepsJsonLibrariesWithoutAssets, which can be set to false to disable deps.json library trimming