Guard PublishDir exclusion against project root directory#53923
Merged
jjonescz merged 3 commits intodotnet:release/10.0.4xxfrom Apr 23, 2026
Merged
Guard PublishDir exclusion against project root directory#53923jjonescz merged 3 commits intodotnet:release/10.0.4xxfrom
jjonescz merged 3 commits intodotnet:release/10.0.4xxfrom
Conversation
When dotnet publish -o . is used, PublishDir resolves to the project directory. The glob exclusion then excludes all source files, producing an empty assembly. Add a condition to skip the exclusion when PublishDir equals the project directory. Fixes dotnet#53626 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an SDK default item globbing issue where dotnet publish -o . can make PublishDir resolve to the project directory, causing the DefaultItemExcludes glob to exclude all source items and produce an empty assembly.
Changes:
- Add an MSBuild condition to avoid excluding
$(PublishDir)/**whenPublishDiris the project directory. - Add a regression test ensuring compile items are not excluded when
PublishDirpoints at the project root.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/Microsoft.NET.Build.Tests/GivenThereAreDefaultItems.cs | Adds a regression test for PublishDir == project root not excluding compile items. |
| src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets | Guards the PublishDir exclusion so it doesn’t wipe out default source items when publishing to .. |
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.
When
dotnet publish -o .is used,PublishDirresolves to the project directory. The glob exclusion then excludes all source files, producing an empty assembly. Add a condition to skip the exclusion whenPublishDirequals the project directory.Fixes #53626