Skip to content

Add anti-pattern for forking a project instance via <MSBuild> with path-neutral global properties - #770

Merged
ViktorHofer merged 1 commit into
mainfrom
dotnet-msbuild-global-property-fork
Jun 16, 2026
Merged

ViktorHofer merged 1 commit into
mainfrom
dotnet-msbuild-global-property-fork

Conversation

@dsplaisted

Copy link
Copy Markdown
Member

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/IntermediateOutputPath as 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-antipatterns
    • New AP-22 in references/additional-antipatterns.md covering 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 + DependsOnTargets with a cycle guard; (b) let the producer publish in its own build and have the consumer sequence it via a non-output ProjectReference instead of re-publishing it.
    • Updated the SKILL.md pointer (AP-16 through AP-22) and the quick-reference checklist.
  • dotnet-msbuild/skills/check-bin-obj-clash
    • Added the matching cause (self or cross-project <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 _IsPublishing row in the global-properties table.
  • Tests
    • Added a publish-on-build smell to the msbuild-antipatterns review fixture (LibA.csproj) and a matching rubric line in eval.yaml and eval.vally.yaml.

Two tightly-coupled skills are touched intentionally: AP-22 catches the smell at authoring/review time, check-bin-obj-clash catches the runtime symptom from a binlog. They cross-reference each other.

…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]>
@dsplaisted
dsplaisted requested a review from ViktorHofer as a code owner June 16, 2026 00:03
Copilot AI review requested due to automatic review settings June 16, 2026 00:03
@dsplaisted
dsplaisted requested a review from JanKrivanek as a code owner June 16, 2026 00:03
@dsplaisted
dsplaisted requested a review from a team June 16, 2026 00:03
@github-actions

Copy link
Copy Markdown
Contributor

Skill Coverage Report

Plugin Skill Covered Coverage
⚠️ dotnet-msbuild check-bin-obj-clash 9/13 69.2%
Uncovered: dotnet-msbuild/check-bin-obj-clash
  • [WorkflowStep] Step 2: Get an overview and list projects (line 48)
  • [WorkflowStep] Step 5: Check for double writes (line 62)
  • [WorkflowStep] Step 2: Replay the Binary Log to Text (line 78)
  • [WorkflowStep] Step 3: List All Projects (line 84)

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

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-clash guidance 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.

@github-actions github-actions Bot added the pr-state/ready-for-eval PR is mergeable and awaiting evaluation label Jun 16, 2026
github-actions Bot added a commit that referenced this pull request Jun 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Skill Validation Results

Skill Scenario Quality Skills Loaded Overfit Verdict
msbuild-antipatterns Review MSBuild files for anti-patterns and style issues 4.0/5 → 5.0/5 🟢 ✅ msbuild-antipatterns; tools: skill, glob, edit / ⚠️ NOT ACTIVATED ✅ 0.07 ✅ [1]
msbuild-antipatterns Add a module to an F# project 5.0/5 → 5.0/5 ⚠️ NOT ACTIVATED ✅ 0.07 ❌ [2]
msbuild-antipatterns Fix broken file order causing FS0039 4.0/5 → 4.0/5 ⚠️ NOT ACTIVATED ✅ 0.07 ❌ [3]
msbuild-antipatterns Add a signature file to define public API 5.0/5 → 5.0/5 ⚠️ NOT ACTIVATED ✅ 0.07 ❌ [4]
check-bin-obj-clash Diagnose bin/obj output path clashes 4.0/5 → 5.0/5 🟢 ✅ check-bin-obj-clash; tools: binlog-binlog_double_writes, binlog-binlog_diagnose, binlog-binlog_properties, skill, binlog-binlog_evaluations, binlog-binlog_evaluation_global_properties, binlog-binlog_evaluation_properties, binlog-binlog_overview / ✅ check-bin-obj-clash; tools: glob, binlog-binlog_double_writes, skill, binlog-binlog_evaluations, binlog-binlog_properties, binlog-binlog_evaluation_properties ✅ 0.14 ✅ [5]

[1] ⚠️ High run-to-run variance (CV=189%) — consider re-running with --runs 5
[2] ⚠️ High run-to-run variance (CV=55%) — consider re-running with --runs 5. (Plugin) Quality unchanged but weighted score is -4.5% due to: tokens (108709 → 195887)
[3] (Plugin) Quality unchanged but weighted score is -1.4% due to: tokens (82694 → 117830)
[4] (Plugin) Quality unchanged but weighted score is -3.6% due to: tokens (85124 → 140992)
[5] ⚠️ High run-to-run variance (CV=5817%) — consider re-running with --runs 5

Model: claude-opus-4.6 | Judge: claude-opus-4.6

🔍 Full Results - additional metrics and failure investigation steps

To investigate failures, paste this to your AI coding agent:

For PR 770 in dotnet/skills, download eval artifacts with gh run download 27588038846 --repo dotnet/skills --pattern "skill-validator-results-*" --dir ./eval-results, then fetch https://raw.githubusercontent.com/dotnet/skills/0442634284245e94e6fccb131cf53497c5503f47/eng/skill-validator/src/docs/InvestigatingResults.md and follow it to analyze the results.json files. Diagnose each failure, suggest fixes to the eval.yaml and skill content, and tell me what to fix first.

▶ Sessions Visualisation -- interactive replay of all evaluation sessions
📊 Session Analytics (preview) -- aggregated metrics across evaluation sessions

@github-actions github-actions Bot added waiting-on-review PR state label and removed pr-state/ready-for-eval PR is mergeable and awaiting evaluation labels Jun 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Evaluation passed for 0442634. cc @ViktorHofer @JanKrivanek @dotnet/skills-msbuild-reviewers — please review.

@ViktorHofer
ViktorHofer merged commit 8a437b1 into main Jun 16, 2026
38 checks passed
@ViktorHofer
ViktorHofer deleted the dotnet-msbuild-global-property-fork branch June 16, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on-review PR state label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants