Repository navigation
Fix CS0579 flake: exclude nested project dirs from parent project default item globs - #55382
Merged
Merged
Conversation
In test assets where one project file physically contains another project in a subdirectory, the parent project's default SDK item glob (e.g. **/*.cs) would inadvertently pick up generated files (AssemblyInfo.cs, assembly attribute files) from the nested project's obj/ directory. When MSBuild builds the nested project before the parent in a solution build (order is non-deterministic), those generated files exist on disk at glob-evaluation time, causing CS0579 duplicate assembly attribute errors in the parent. Fix: Add DefaultItemExcludes to each parent project that physically contains a nested child project, excluding the nested project's entire subtree. Assets updated: - TestAppWithSlnAndCsprojInSubDirVS/foo/foo.csproj: exclude bar\** - TestAppWithSlnAndCsprojInSubDir/App.csproj: exclude src\** - TestAppWithSlnAndCsprojInSubDirToRemove/App.csproj: exclude src\** - TestAppWithSlnAndLastCsprojInSubDirToRemove/App.csproj: exclude src\** - TestAppWithSlnAndCsprojInSubDirVSErrors/Base/Test.csproj: exclude Second\** - TestAppWithSlnAndCsprojInSubDirVSErrors/Base/TestCollision.csproj: exclude Second\** - TestAppWithSlnAndCsprojInSubDirVSErrors/Base/Second/Test.csproj: exclude Third\** - TestAppWithSlnAndCsprojInSubDirVSErrors/Base/Second/Second.csproj: exclude Third\** - TestAppWithSlnAndCsprojInSubDirVSErrors/Base/Second/TestCollision.csproj: exclude Third\** Fixes #55358 Co-authored-by: Copilot App <[email protected]> Copilot-Session: f81afe5d-ffa8-473c-adf5-7c27f6018ab2
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses an intermittent CI flake (CS0579 duplicate assembly attributes) caused by SDK default source globs in a parent test-asset project unintentionally picking up generated obj/**/*.cs files from a physically nested child project directory when solution build ordering varies.
Changes:
- Add
DefaultItemExcludesentries to parent test-asset projects to exclude nested child-project directory subtrees from default item globs. - Apply the same exclusion pattern across several nested/stacked test assets (including the
VSErrorsvariant) to prevent similar duplicate-attribute races.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/TestAssets/TestProjects/TestAppWithSlnAndLastCsprojInSubDirToRemove/App.csproj | Excludes src\** from default item globs to avoid compiling nested child project artifacts. |
| test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInSubDirVSErrors/Base/TestCollision.csproj | Excludes Second\** subtree to prevent nested build outputs from being globbed into the parent. |
| test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInSubDirVSErrors/Base/Test.csproj | Excludes Second\** subtree to prevent nested build outputs from being globbed into the parent. |
| test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInSubDirVSErrors/Base/Second/TestCollision.csproj | Excludes Third\** subtree to prevent deeper nested build outputs from being globbed into the parent. |
| test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInSubDirVSErrors/Base/Second/Test.csproj | Excludes Third\** subtree to prevent deeper nested build outputs from being globbed into the parent. |
| test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInSubDirVSErrors/Base/Second/Second.csproj | Excludes Third\** subtree to prevent deeper nested build outputs from being globbed into the parent. |
| test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInSubDirVS/foo/foo.csproj | Excludes bar\** subtree to prevent nested project build outputs from being globbed into the parent. |
| test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInSubDirToRemove/App.csproj | Excludes src\** from default item globs to avoid compiling nested child project artifacts. |
| test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInSubDir/App.csproj | Excludes src\** from default item globs to avoid compiling nested child project artifacts. |
dsplaisted
approved these changes
Jul 21, 2026
This was referenced Jul 22, 2026
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.
Summary
Fixes intermittent CS0579 "duplicate assembly attribute" errors in CI, tracked in #55358.
Root Cause
Several test assets contain a parent project file (e.g.
App.csproj) that physically nests a child project in a subdirectory (e.g.src/Lib/Lib.csproj). The SDK's default item glob (**/*.cs) is scoped to exclude only the parent's ownobj/directory. When MSBuild schedules the child project to build before the parent in a solution build (which is non-deterministic), the child's generated files (AssemblyInfo.cs,.NETStandard...AssemblyAttributes.cs) are written tosrc/Lib/obj/— which falls inside the parent's glob — and get double-compiled into the parent, producing CS0579.The failure is intermittent because project build ordering in a solution is scheduler-dependent: when the parent builds first (its
obj/doesn't yet contain the child's artifacts), it passes cleanly.Fix
Add
<DefaultItemExcludes>$(DefaultItemExcludes);{subdir}\**</DefaultItemExcludes>to each parent project that physically contains a child project, excluding the nested subtree entirely from the parent's default globs. The solution still builds the child correctly because MSBuild drives it from the child's own.csproj.Files changed
TestAppWithSlnAndCsprojInSubDirVSfoo/foo.csprojbar\**TestAppWithSlnAndCsprojInSubDirApp.csprojsrc\**TestAppWithSlnAndCsprojInSubDirToRemoveApp.csprojsrc\**TestAppWithSlnAndLastCsprojInSubDirToRemoveApp.csprojsrc\**TestAppWithSlnAndCsprojInSubDirVSErrorsBase/Test.csprojSecond\**TestAppWithSlnAndCsprojInSubDirVSErrorsBase/TestCollision.csprojSecond\**TestAppWithSlnAndCsprojInSubDirVSErrorsBase/Second/Test.csprojThird\**TestAppWithSlnAndCsprojInSubDirVSErrorsBase/Second/Second.csprojThird\**TestAppWithSlnAndCsprojInSubDirVSErrorsBase/Second/TestCollision.csprojThird\**