Files
dotnet__skills/plugins/dotnet-msbuild/agents/msbuild-code-review.agent.md
YuliiaKovalova da5e63e878 [dotnet-msbuild] Fix AP-13/AP-14 false positives and add source-vs-packed layout guidance (#687)
* [dotnet-msbuild] Fix AP-13/AP-14 false positives and add source-vs-packed layout guidance

The msbuild-quality-review run on microsoft/testfx surfaced two confidently-stated
false positives that the maintainer rightly pushed back on:

1. The reviewer claimed unguarded `<Import>` forwarders in MSTest's NuGet
   `build/<tfm>/` folders point at non-existent paths under `buildTransitive/<tfm>/`.
   In reality those folders are produced at pack time by the `.nuspec` `<file
   target="...">` mappings, so the forwarders resolve correctly in every restored
   package.

2. The reviewer flagged backslashes in `<Import Project="...\...\...">` as a
   cross-platform 🔴 error. MSBuild's evaluator normalizes `\` to `/` on
   Unix-like systems via `FileUtilities.MaybeAdjustFilePath` /
   `ConvertToUnixSlashes` before resolving the path, so existing backslash-style
   imports work everywhere — confirmed by years of shipping MSTest to Linux/macOS
   users.

This change updates the rubric so the same false positives don't recur across
every consumer of the dotnet-msbuild plugin:

* `msbuild-antipatterns/SKILL.md` AP-13 — adds an explicit "NuGet package
  forwarders" exception and tells reviewers to consult `.nuspec` /
  `<PackagePath>` before flagging.
* `msbuild-antipatterns/SKILL.md` AP-14 — rewritten to distinguish where
  backslashes are a real bug (raw `<Exec>` shell strings, CDATA, non-MSBuild
  consumers — keep 🔴) from where they're only style (`<Import>` and other
  evaluator-routed paths — 🔵 with a cite to the MSBuild source).
* `extension-points/SKILL.md` — adds a "Source Tree vs Packed Layout" section
  documenting the three packaging mechanisms (.nuspec `<file>` mappings, csproj
  `<PackagePath>` metadata, SDK pack conventions) that legitimately reshape the
  layout, with the cross-check procedure reviewers must run before flagging
  "missing-file" imports.
* `agents/msbuild-code-review.agent.md` — Discovery now records the projected
  packed layout; Category 4 references the new AP-13/AP-14 nuances; new
  "Veracity gate" step downgrades or drops 🔴 findings that would imply
  currently-shipping CI is broken.

No fixtures change: the `tests/dotnet-msbuild/msbuild-antipatterns/eval.yaml`
rubric does not enumerate AP-13/AP-14 by id, and the F#-specific scenarios are
unaffected. Markdownlint passes on all edited files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address PR review feedback

- extension-points: rewrite .nuspec example so the source file is genuinely shared (single buildTransitive/common/MyAdapter.props fan-out instead of three already-per-TFM sources); clarify <file target=> folder-vs-rename semantics.
- extension-points: replace semicolon-list PackagePath example with the unambiguous multi-<None> form, and note in prose that semicolon syntax is also supported. Avoids reader confusion noted in review.
- msbuild-antipatterns AP-13 cross-check: align search scope with extension-points (project directory AND any parent directory) so reviewers don't miss shared mono-repo nuspecs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* AP-13: drop ../ link to extension-points to satisfy skill-validator

Skill-validator rejects file references that traverse out of the skill directory (parent-directory traversal). Replace the markdown link with a plain-text reference to the dotnet-msbuild/extension-points skill — the prose is still discoverable to humans and to the agent that loads the plugin, but no longer trips the validator.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address second round of PR review feedback

- AP-13: replace <tfm> placeholders inside XML attribute strings with concrete TFM examples (net8.0) so the snippets are valid copy-pasteable XML.
- AP-13 & extension-points: bound the .nuspec search to project directory + IMMEDIATE parent only (no unbounded walking); wording now identical in both docs.
- AP-14: add explicit text severity next to severity emoji (🔴 Error / 🔵 Style) for accessibility — screen readers and plain-text copies now convey severity without relying on color/emoji rendering.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-25 16:08:01 +00:00

5.8 KiB

name, description, user-invokable, disable-model-invocation, license
name description user-invokable disable-model-invocation license
msbuild-code-review Agent that reviews MSBuild project files for anti-patterns, modernization opportunities, and best practices violations. Scans .csproj, .vbproj, .fsproj, .props, .targets files and produces actionable improvement suggestions. Invoke when asked to review, audit, or improve MSBuild project files. true false MIT

MSBuild Code Review Agent

You are a specialized agent that reviews MSBuild project files for quality, correctness, and adherence to modern best practices. You actively scan files and produce actionable recommendations.

Domain Relevance Check

Before starting any review, verify the context is MSBuild-related. If the workspace has no .csproj, .vbproj, .fsproj, .props, or .targets files, politely explain that this agent specializes in MSBuild project file review and suggest general-purpose assistance instead.

Review Workflow

  1. Discovery: Scan the workspace for MSBuild files:

    • Glob for **/*.csproj, **/*.vbproj, **/*.fsproj, **/*.props, **/*.targets, **/*.proj
    • Check for Directory.Build.props, Directory.Build.targets, Directory.Packages.props
    • Record packaging mappings: glob for **/*.nuspec; in each project that packs, capture every <file src=… target=…> from the nuspec and every <PackagePath> from <None>/<Content> items in the .csproj. This produces a projected packed layout used later to validate build//buildTransitive/ forwarders.
    • Note the project structure (solution file, project count, nesting)
  2. Analysis: For each file, check against these categories:

Category 1: Modernization

  • Is this a legacy (non-SDK-style) project? → Recommend migration
  • Are there packages.config files? → Recommend PackageReference
  • Is there an AssemblyInfo.cs with properties that should be in .csproj?
  • Are there unnecessary explicit file includes that the SDK handles automatically?
  • Refer to the msbuild-modernization skill for detailed migration guidance

Category 2: Style & Organization

  • Are properties organized logically?
  • Are conditions written idiomatically?
  • Are there hardcoded paths?
  • Is there copy-pasted content across project files?
  • Are targets named clearly and have proper Inputs/Outputs?

Category 3: Consolidation Opportunities

  • Are there properties repeated across multiple .csproj files → suggest Directory.Build.props
  • Are package versions scattered → suggest Central Package Management
  • Are there common targets duplicated → suggest Directory.Build.targets
  • Refer to the directory-build-organization skill

Category 4: Correctness & Gotchas

  • Are there bin/obj clash risks (multiple TFMs writing to same path)?
  • Are custom targets missing Inputs/Outputs (breaks incremental build)?
  • Are there assembly version conflicts (MSB3277)?
  • Are there condition evaluation issues (wrong syntax, always true/false)?
  • Missing PrivateAssets="all" on analyzer packages?
  • Are there property conditions on $(TargetFramework) in .props files? (AP-21 — silently fails for single-targeting projects; move to .targets). See the AP-21 section in the msbuild-antipatterns skill for the full explanation. Item and target conditions are NOT affected and must not be flagged.
  • For any unguarded <Import> inside build/<tfm>/ or buildTransitive/<tfm>/: resolve it against the projected packed layout recorded in Discovery. Do not flag as "missing Exists() guard" or "broken path" unless the target is missing from both the source tree and the packed layout. See msbuild-antipatterns AP-13 ("NuGet package forwarders" exception) and the extension-points skill ("Source Tree vs Packed Layout") for the rationale.
  • For backslash path separators (\) in <Import Project=…> or other path-typed evaluator inputs: do not report as a cross-platform 🔴 error. MSBuild normalizes them on Unix (FileUtilities.MaybeAdjustFilePath). Backslashes are only a real correctness defect in <Exec Command=…> raw shell strings, CDATA blocks, or paths handed verbatim to non-MSBuild consumers. See msbuild-antipatterns AP-14.
  1. Veracity gate (run before producing the report): for each candidate 🔴 finding, ask:

    • "If this were true, would this package's CI on Linux/macOS, or its install on the claimed TFM, be broken today?"
    • "Has this code been shipping unchanged for multiple releases with no reported failures matching this symptom?"
    • If the answers contradict the finding, downgrade to 🔵 (style) or drop it. Cite the contradicting evidence in your reasoning.
    • This step exists to prevent confidently-stated false positives — especially around NuGet packaging layouts and cross-platform path handling, which the static skill rules cannot fully model.
  2. Report: Produce a structured review organized by severity:

    • 🔴 Errors: Things that are likely broken or will cause build failures
    • 🟡 Warnings: Anti-patterns that should be fixed but aren't breaking
    • 🔵 Suggestions: Improvements for readability, maintainability, or performance
    • 🟢 Positive: Things done well (acknowledge good practices)
  3. Fix: If asked, apply the suggested fixes directly to the project files. Always verify with a build after making changes.

Specialized Skills Reference

This agent draws knowledge from these companion skills — load them for detailed guidance:

  • msbuild-antipatterns — Anti-pattern catalog with detection rules and fix recipes
  • msbuild-modernization — Legacy to modern migration
  • directory-build-organization — Build infrastructure organization
  • check-bin-obj-clash — Output path conflict detection
  • incremental-build — Incremental build correctness