Repository navigation
Add anti-pattern for forking a project instance via <MSBuild> with path-neutral global properties - #770
Conversation
…th-neutral global properties
Adds msbuild-antipatterns AP-22 (in references/additional-antipatterns.md): using
the <MSBuild> task to build/publish a project with an extra global property that
does not change the output path forks a distinct instance sharing the same
OutputPath/IntermediateOutputPath as the instance the graph already builds,
causing duplicate builds and parallel-write races on PDBs, *.sourcelink, and
project.assets.json. Covers both shapes:
(a) a project re-invoking itself (publish-on-build), and
(b) project A invoking Build/Publish on another project B it consumes
(e.g. a test/layout project publishing a tool) — the more common trigger.
GOOD fixes: (a) static _IsPublishing + DependsOnTargets with a cycle guard;
(b) let the producer publish in its own build and have the consumer sequence it
with a non-output ProjectReference instead of re-publishing it. Also updates the
SKILL.md pointer (AP-16 through AP-22) and the quick-reference checklist.
Extends check-bin-obj-clash with the matching cause (self or cross-project
<MSBuild> Build/Publish with a path-neutral global property), binlog-based
detection via the evaluations/global-properties/double_writes tools, the two
fixes, and an _IsPublishing row in the global-properties table.
Adds eval coverage: a publish-on-build smell in the msbuild-antipatterns review
fixture (LibA.csproj) plus a matching rubric line in eval.yaml and eval.vally.yaml.
Co-authored-by: Copilot <[email protected]>
Skill Coverage Report
Uncovered:
|
There was a problem hiding this comment.
Pull request overview
Adds a new MSBuild anti-pattern (AP-22) to help reviewers spot a common “duplicate project instance” hazard caused by invoking <MSBuild> with path-neutral extra global properties (often _IsPublishing), plus related guidance in the existing bin/obj clash diagnostic skill and its evaluation fixtures.
Changes:
- Documented new anti-pattern AP-22 with BAD→GOOD transforms for both self-invocation (“publish-on-build”) and cross-project publish invocation scenarios.
- Expanded
check-bin-obj-clashguidance to include binlog-based detection and remediation patterns for the same root cause. - Updated test fixtures and rubrics to include the new smell and expected identification.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/dotnet-msbuild/msbuild-antipatterns/LibA/LibA.csproj | Adds a publish-on-build <MSBuild> self-invocation fixture to represent AP-22 in the review scenario. |
| tests/dotnet-msbuild/msbuild-antipatterns/eval.yaml | Updates the evaluation rubric to require identifying the new publish-on-build / path-neutral-global-property smell. |
| tests/dotnet-msbuild/msbuild-antipatterns/eval.vally.yaml | Mirrors the rubric update for vally-based evaluation. |
| plugins/dotnet-msbuild/skills/msbuild-antipatterns/SKILL.md | Updates the skill’s pointer to include AP-22 coverage. |
| plugins/dotnet-msbuild/skills/msbuild-antipatterns/references/additional-antipatterns.md | Adds the AP-22 write-up and checklist entry. |
| plugins/dotnet-msbuild/skills/check-bin-obj-clash/SKILL.md | Adds a new documented failure mode + detection/fix guidance for <MSBuild> publish/build with path-neutral global properties (self or cross-project). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Skill Validation Results
[1] Model: claude-opus-4.6 | Judge: claude-opus-4.6 🔍 Full Results - additional metrics and failure investigation steps
▶ Sessions Visualisation -- interactive replay of all evaluation sessions |
|
✅ Evaluation passed for |
Summary
Adds a new MSBuild anti-pattern (AP-22) plus guidance for using the
<MSBuild>task to build/publish a project with an extra global property that doesn't change the output path. This is a common cause of MSBuild issues. We've hit it recently in .NET several times when switching projects to NativeAOT and trying to consume their outputs from other projects.Because a project instance's identity is path + global properties, setting global properties on a build of a project that's already being built forks a second instance that still resolves to the same
OutputPath/IntermediateOutputPathas the instance the graph already builds — so the project builds twice and the two instances can race writing the same files (PDBs,*.sourcelink/NativeAOT intermediates,project.assets.json).This error case is somewhat covered in the check-bin-obj-clash skill (which this PR also updates), but that skill requires investigating a binlog for the build, while this anti-pattern tries to recognize the issue just from looking at the project file.
Most recently we had to revert a change in dotnet/dotnet#7124 because of this. Other related PRs where we hit this or were working out the pattern to apply:
What changed
dotnet-msbuild/skills/msbuild-antipatternsreferences/additional-antipatterns.mdcovering both shapes — (a) a project re-invoking itself (publish-on-build), and (b) project A publishing another project B it consumes — each with a BAD→GOOD transform. GOOD fixes: (a) static_IsPublishing+DependsOnTargetswith a cycle guard; (b) let the producer publish in its own build and have the consumer sequence it via a non-outputProjectReferenceinstead of re-publishing it.SKILL.mdpointer (AP-16 through AP-22) and the quick-reference checklist.dotnet-msbuild/skills/check-bin-obj-clash<MSBuild>Build/Publish with a path-neutral global property), with binlog-based detection using the skill's documented MCP tools (evaluations/evaluation_global_properties/double_writes, plus the project tree to tell self vs cross-project), both fixes, and an_IsPublishingrow in the global-properties table.msbuild-antipatternsreview fixture (LibA.csproj) and a matching rubric line ineval.yamlandeval.vally.yaml.Two tightly-coupled skills are touched intentionally: AP-22 catches the smell at authoring/review time,
check-bin-obj-clashcatches the runtime symptom from a binlog. They cross-reference each other.