Skip to content

Fix CS0579 flake: exclude nested project dirs from parent project default item globs - #55382

Merged
MichaelSimons merged 1 commit into
mainfrom
michaelsimons-investigate-ci-flake-55358
Jul 21, 2026
Merged

MichaelSimons merged 1 commit into
mainfrom
michaelsimons-investigate-ci-flake-55358

Conversation

@MichaelSimons

Copy link
Copy Markdown
Member

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 own obj/ 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 to src/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

Asset Parent project Exclusion added
TestAppWithSlnAndCsprojInSubDirVS foo/foo.csproj bar\**
TestAppWithSlnAndCsprojInSubDir App.csproj src\**
TestAppWithSlnAndCsprojInSubDirToRemove App.csproj src\**
TestAppWithSlnAndLastCsprojInSubDirToRemove App.csproj src\**
TestAppWithSlnAndCsprojInSubDirVSErrors Base/Test.csproj Second\**
TestAppWithSlnAndCsprojInSubDirVSErrors Base/TestCollision.csproj Second\**
TestAppWithSlnAndCsprojInSubDirVSErrors Base/Second/Test.csproj Third\**
TestAppWithSlnAndCsprojInSubDirVSErrors Base/Second/Second.csproj Third\**
TestAppWithSlnAndCsprojInSubDirVSErrors Base/Second/TestCollision.csproj Third\**

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
Copilot AI review requested due to automatic review settings July 20, 2026 16:06
@azure-pipelines

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 DefaultItemExcludes entries 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 VSErrors variant) 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.

@MichaelSimons
MichaelSimons requested a review from a team July 20, 2026 16:09
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.

3 participants