AGENT SKILL

MSBuild 构建故障排查

msbuild

使用二进制日志调查 MSBuild 构建失败、诊断构建性能,并审查构建 XML 与扩展契约。适用于 dotnet build、restore、pack 或 publish 失败;.binlog 捕获与回放;project、props 与 targets 条件;自定义 target 的输入/输出;Import/Exists 钩子与打包的 NuGet 导入;求值、编译、复制缓慢或无变更构建;以及受控的耗时对比。不适用于旧版或非 SDK 项目迁移、框架或包升级、SDK 安装、C# 重构、运行时性能剖析、构建成功后的断言,或非 MSBuild 构建。

License 许可
MIT
最近更新
2026-11-14
Stars
★ 1
Forks
1

01 前言 Front Matter

name
msbuild
license
MIT
description
Investigates MSBuild build failures, diagnoses build performance, and reviews build XML and extension contracts using binary logs. Use for failing dotnet build, restore, pack, or publish; .binlog capture and replay; project, props, and targets conditions; custom-target inputs/outputs; Import/Exists hooks and packed NuGet imports; slow evaluation, compilation, copying, or no-change builds; and controlled timing comparisons. Not for legacy or non-SDK project migration, framework or package upgrades, SDK installation, C# refactoring, runtime profiling, assertions after a successful build, or non-MSBuild builds.

02 资源文件 14

03 SKILL.md 正文

<!-- cratis-ai-managed: skills/msbuild/SKILL.md -->

<!-- Modified by Cratis from dotnet's original (MIT): frontmatter, applicability, navigation and the changes listed in NOTICE. Upstream: https://github.com/dotnet/skills (plugins/dotnet/skills/msbuild/SKILL.md; see NOTICE) -->

MSBuild troubleshooting

Cratis rules in .cratis/ai/rules/ (including csharp.md, specs.csharp.md, and orleans.md) and the cratis-* skills win where they differ.

This is the entry skill. Choose troubleshooting, performance, or authoring review, then read only the relevant local references. The references retain the content and identities of the original MSBuild skills, with correctness fixes; they are not separate skills to activate.

Start with the task and evidence

For tasks that need a checkout, discover the relevant project/solution, shared build files, SDK selection, and repository build instructions in the current workspace. Preserve the original command, working directory, configuration, target framework, runtime identifier, global properties, and target. Ask only for consequential information that cannot be discovered.

An existing .binlog can be the only available artifact. Analyze it before requesting a new build; paths inside it do not prove a checkout exists locally. For a self-contained static review or advisory question, use the supplied XML and relevant references; do not require a checkout, restore, build, or binlog.

For a mixed request, fix correctness before measuring successful builds, and keep authoring review separate from a performance experiment. A failing test assertion after a successful build is not an MSBuild failure.

1. Troubleshoot build issues

Goal: identify the independent root causes and make the smallest repair, not a broad cleanup.

Situation Read Action
A build failed and a binary log exists binlog-failure-analysis Replay the log with MSBuild; connect errors to the responsible project instance, target, and task. Separate root causes from cascading failures.
The failure needs evidence and no matching log exists binlog-generation, then failure analysis Capture the original invocation once, verify the artifact, and analyze it.
A project/build file has incorrect conditions, items, properties, or output paths msbuild-antipatterns Select the relevant catalog entries and check their exceptions before changing anything.
Imports or build hooks are missing, overwritten, or run in the wrong order extension-points Inspect the import contract, discovery order, and packed NuGet layout rather than hiding a required failure.
Outputs are stale or required work is skipped incremental-build Prove which input, output, timestamp, item, or condition makes the decision wrong. Correctness takes priority over speed.

After a repair, rerun the original failing scenario and check affected dependents. If only a log is available, provide an evidence-backed proposed fix and say it was not applied or rebuilt. Do not turn a targeted failure investigation into solution-wide authoring cleanup.

2. Diagnose and improve build performance

Goal: measure the reported scenario, identify its bottleneck, change one cause, and compare equivalent builds without losing required behavior.

  1. Reuse matching measurements. If they are missing, establish the relevant baseline before editing configuration; do not time a failed build as a successful baseline.
  2. Classify evaluation versus target/task execution. Inclusive target totals and dependency waits are not additive wall time or proof of CPU utilization.
  3. Follow the measured branch below. Do not apply every optimization in every reference.
  4. Repeat the same scenario, command, input change, and instrumentation. Report spread/noise and correctness checks; an isolated faster run is not proof of improvement.
Situation Read Keep distinct
No trustworthy before/after measurements, or a baseline/controlled optimization is requested build-perf-baseline Cold-output, warm changed-input, and no-change builds; restore/cache state; ordinary Build versus forced Rebuild.
The expensive work is not yet identified, or compiler/analyzer/reference/restore time dominates build-perf-diagnostics Actual task cost versus orchestration waits, overlapping durations, and missing instrumentation.
Time is spent before target execution, in globs, imports, or property evaluation eval-performance Evaluation versus execution; legitimate versus accidental project instances.
Content copies or output I/O dominate copy-to-output-directory Copy mode/version support, unchanged copies, and the intended handling of a modified destination.
A second unchanged build recompiles/regenerates, or incremental behavior is broken incremental-build Expected invalidation versus missing tracking; changed/added/removed inputs and missing outputs.

Stop when the suspected bottleneck is not supported by evidence, results fall within noise, or correctness regresses. Report missing measurements rather than manufacturing a complete baseline.

3. Review build authoring

Goal: improve project/build-file structure and extension contracts while preserving behavior. This route means MSBuild authoring cleanup, not an implicit framework, package, language, or legacy project-system migration.

Requested change Read Preserve
Review/clean up project files, shared properties, item declarations, or custom targets msbuild-antipatterns Intentional overrides, F# source order, required imports, package assets, and actual input/output contracts.
Review/improve hooks, imports, shared-file discovery, or NuGet build extensions extension-points Prior hooks, evaluation order, direct/transitive consumer behavior, and the packed layout.
Restructure generation or copying as part of cleanup incremental-build and copy-to-output-directory, as applicable First-build and no-change behavior, invalidation, generated-item registration, and output completeness.

Record the existing contract before editing. Review only relevant catalog entries; a matching text pattern is not proof of a defect. Leave already-correct patterns unchanged. Validate the original configurations, relevant consumers, and affected incremental/pack/publish behavior.

Shared evidence and safety

  • For capture-only requests, use binlog-generation, report the new artifact and original exit code, and stop. For analysis, use MSBuild replay, never binary-file text parsing. Replay success and replay duration are not the recorded build's result or duration.
  • Resolve these files relative to this skill. Do not load the original plugin's skills or search other installations/checkouts. If a bundled reference is missing, allow one listing of references, report the gap, and do not pretend its guidance was followed.
  • Do not clean outputs/caches, stop shared build servers, disable diagnostics, change SDKs, or serialize builds as generic fixes. Scope any necessary destructive experiment to approved, owned outputs. Keep binary and replayed logs local unless sharing is authorized.
  • Distinguish recorded facts from hypotheses. Missing source, log detail, tools, or platform support must be reported explicitly, not replaced with assumed values or invented verification.

Completion

Return the selected task, the cause/bottleneck or authoring decision, supporting evidence, and the minimal change made or proposed. State when no change is needed. Give the exact verification and result, distinguishing successful, failed, and not-run checks; performance work also needs comparable measurements and uncertainty. Keep the response proportional to the task.

Cratis: Only as a labelled timing experiment; restore analyzers and warnings-as-errors and run the real gate before finishing.

Reference navigation

  • Read references/antipatterns/additional-antipatterns.md when working on additional antipatterns.
  • Read references/antipatterns/incremental-build-inputs-outputs.md when working on incremental build inputs outputs.
  • Read references/antipatterns/private-assets.md when working on private assets.

04 同仓库更多 Skills

Cratis
Cratis/Specifications

.NET SIMD 向量化代码

vectorization

设计、实现、优化和审查 .NET 中的 SIMD 代码:使用 TensorPrimitives、Vector64、Vector128、Vector256、Vector512 或硬件内部函数将标量循环向量化,并审查现有 SIMD 代码(包括泛型 Vector 类型)的契约等价性、尾部处理、内存安全性、可移植性、回退方案和实测性能。当正在编写或审查 .NET 循环或 SIMD 例程时使用。不用于与 SIMD 无关的性能工作。

软件开发工程师性能剖析与优化
★ 1
Cratis
Cratis/Specifications

MSBuild自定义目标编写

target-authoring

编写自定义 MSBuild target 的规范模式:DependsOnTargets 与 BeforeTargets、AfterTargets 的区别,Build-to-CoreBuild 三级模式,以及 XxxDependsOn 链式扩展模式。用于诊断或修复自定义 target 的反模式:Directory.Build.targets 重新定义 SDK target、target 替换而非扩展 CompileDependsOn、Outputs 与 Returns 误用导致返回过期结果、缺少 Inputs/Outputs 导致不必要的重新构建,或缺少 FileWrites 注册。不适用于增量构建调优或一般反模式审查(使用 msbuild 技能),也不适用于非 MSBuild 构建系统。

软件开发工程师开发环境与工具链管理
★ 1
Cratis
Cratis/Specifications

.NET测试命令执行

run-tests

选择并运行与仓库兼容的 .NET 测试命令:针对 MSTest、xUnit、NUnit 和 TUnit 的 classic、VSTest、bridged MTP 或 native MTP 语法。在运行 .NET 测试或需要给出测试命令/标志时使用:运行全部测试、单个测试、测试类、类别、trait 或目标框架、组合筛选器、--filter-query、--no-build、--diag、TRX、覆盖率收集、崩溃或挂起转储、筛选错误或无法识别的选项。不适用于仅做平台识别(使用 platform-detection)、编写或调试测试代码、解读覆盖率报告(使用 coverage-analysis)、CI 调查、迁移或持续的热重载循环。

测试工程师测试与质量保障
★ 1
Cratis
Cratis/Specifications

.NET 性能剖析

profiling

使用免费的官方 .NET 诊断 CLI 工具在代码仓库中进行性能剖析和运行时调查:CPU、GC 压力、分配增长、异常风暴、锁竞争和慢代码。当 .NET 应用程序需要性能或运行时剖析时使用。不适用于用临时跟踪替代真实的性能或负载测试、无暂停风险计划的生产堆内存采集、崩溃转储(使用 dump-collect),或基准测试设计(使用 microbenchmarking)。

软件开发工程师性能剖析与优化
★ 1
Cratis
Cratis/Specifications

.NET 测试平台识别

platform-detection

识别 .NET 项目的测试平台、框架、命令模式,以及 SDK 样式与经典项目系统,并解析 global.json、项目文件、packages.config、Directory.Build.props 和 Directory.Packages.props 对 MSTest、xUnit、NUnit 和 TUnit 的优先级。当询问“使用哪种测试平台或框架”“VSTest 还是 MTP”或“该项目使用什么测试运行器”时使用,包括桥接设置、UseVSTest 退出选项,以及 VSTest/MTP 配置冲突。不适用于运行或筛选测试、命令、标志、TRX、转储或测试命令错误(使用 run-tests),也不适用于热重载或迁移请求。

测试工程师测试与质量保障
★ 1
Cratis
Cratis/Specifications

Orleans 分布式系统设计

orleans

从每种原语的用途和失效模型出发设计 Microsoft Orleans 系统:grain、数字孪生、状态与数据库、事务、消息传递、流(streams)、计时器(timers)、提醒(reminders)、Durable Jobs(持久作业)、无状态工作进程、grain 服务、启动与托管。当任务需要做出 Orleans 设计决策时使用:检查版本与拓扑、选择原语、实现并验证。不适用于其他 actor 技术栈、批处理、纯关系型 CRUD,或不涉及 Orleans 决策的建议。

系统架构师系统架构设计模式
★ 1