incremental-build
できること
このスキルは、変更がないのに2回目のビルドでMSBuildが対象を再ビルドしてしまう理由を探し、設定を直します。変更なしのビルドが初回のビルドと同じくらい遅い開発者向けです。
使う場面
- ✓何も変更していないのにビルド全体が再実行されるとき。
- ✓カスタムターゲットが、スキップされずに毎回実行されるとき。
- ✓初回は速いのに、2回目以降のビルドが遅いとき。
スキルのリンク
https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/incremental-build/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“何も変更していないのに、.NETのビルドがプロジェクト全体を再ビルドします。原因を調べて直してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは遅いターゲットの入力と出力のタイムスタンプを比べ、入力や出力の欠落、追跡対象の外で書き込まれるファイルを探します。そのうえで修正案を示し、同じビルドを2回実行して確認します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Required diagnosis output
For every diagnose or explain request, the final answer must explicitly cover
all of these points, even when the immediate cause is simply missing
Inputs/Outputs:
- the target and exact root-cause evidence;
- the actual input/output timestamp comparison;
- missing, deleted, cleaned, or rewritten outputs;
- complete inputs, including dynamic or volatile inputs;
- evaluated input/output paths and one-to-one mapping when item lists are batched;
- two identical no-change builds and the expected second-build skip/out-of-date evidence.
Do not edit unless the user asks for a fix. If a check cannot be run, label it
as an unverified check rather than omitting it or claiming success. When
Inputs or Outputs are absent, report timestamp comparison or one-to-one
mapping as not applicable — the incremental mechanism is not engaged, not
as an unverified comparison.
How MSBuild Incremental Build Works
MSBuild's incremental build mechanism allows targets to be skipped when their outputs are already up to date, dramatically reducing build times on subsequent runs.
- Targets with
InputsandOutputsattributes: MSBuild compares the timestamps of all files listed inInputsagainst all files listed inOutputs. If every output file is newer than every input file, the target is skipped entirely. - Without
Inputs/Outputs: The target runs every time the build is invoked. This is the default behavior and the most common cause of slow incremental builds. - Timestamp-based comparison: MSBuild uses file system timestamps (last write time) to determine staleness. It does not use content hashes. This means touching a file (updating its timestamp without changing content) will trigger a rebuild.
<!-- This target is incremental: skipped if Output is newer than all Inputs -->
<Target Name="Transform"
Inputs="@(TransformFiles)"
Outputs="@(TransformFiles->'$(OutputPath)%(Filename).out')">
<!-- work here -->
</Target>
<!-- This target always runs because it has no Inputs/Outputs -->
<Target Name="PrintMessage">
<Message Text="This runs every build" />
</Target>
Why Incremental Builds Break (Top Causes)
Missing Inputs/Outputs on custom targets — Without both attributes, the target always runs. This is the single most common cause of unnecessary rebuilds.
Volatile properties in Outputs path — If the output path includes something that changes between builds (e.g., a timestamp, build number, or random GUID), MSBuild will never find the previous output and will always rebuild.
File writes outside of tracked Outputs — If a target writes files that aren't listed in its
Outputs, MSBuild doesn't know about them. The target may be skipped (because its declared outputs are up to date), but downstream targets may still be triggered.Missing FileWrites registration — Files created during the build but not registered in the
FileWritesitem group won't be cleaned bydotnet clean. Over time, stale files can confuse incremental checks.Glob changes — When you add or remove source files, the item set (e.g.,
@(Compile)) changes. Since these items feed intoInputs, the set of inputs changes and triggers a rebuild. This is expected behavior but can be surprising.Property changes — Properties that feed into
InputsorOutputspaths (e.g.,$(Configuration),$(TargetFramework)) will cause rebuilds when changed. Switching between Debug and Release is a full rebuild by design.NuGet package updates — Changing a package version updates
project.assets.jsonand potentially many resolved assembly paths. This changes the inputs toResolveAssemblyReferencesandCoreCompile, triggering a rebuild.Build server VBCSCompiler cache invalidation — The Roslyn compiler server (
VBCSCompiler) caches compilation state. If the server is recycled (timeout, crash, or manual kill), the next build may be slower even though MSBuild's incremental checks pass, because the compiler must repopulate its in-memory caches.
Diagnosing "Why Did This Rebuild?"
Use binary logs (binlogs) to understand exactly why targets ran instead of being skipped.
Before recommending a fix, report this compact checklist for each target that reran:
- Actual timestamp comparison — name the newest resolved input and oldest resolved output, with their last-write times, and state which input is newer.
- **Output existence
よくある質問
変更なしのビルドとは何ですか?
編集を加えずに2回目のビルドを行うことです。対象はスキップされ、すぐに終わるはずです。
確認なしにファイルを変更しますか?
まず原因を診断します。修正を依頼された場合にだけ修正します。
なぜ変動する値で再ビルドされるのですか?
タイムスタンプやランダムなGUIDのように、ビルドのたびに変わる値が出力パスに含まれると、MSBuildは出力が新しくなったと判断するためです。
詳細
作者による元の説明
Guide for optimizing MSBuild incremental builds. USE FOR: builds slower than expected on subsequent runs, 'nothing changed but it rebuilds anyway', diagnosing why targets re-execute unnecessarily, fixing broken no-op builds. Covers 8 common causes: missing Inputs/Outputs on custom targets, volatile properties in output paths (timestamps/GUIDs), file writes outside tracked Outputs, missing FileWrites registration, glob changes, Visual Studio Fast Up-to-Date Check (FUTDC) issues. Key diagnostic: look for 'Building target completely' vs 'Skipping target' in binlog. DO NOT USE FOR: first-time buil
repo: dotnet/skills
人気
- GitHubのスター
- 5.8k
- ランキング
- #14602
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
create-custom-agent
5.8kVisual Studio Codeのカスタムエージェントのファイルを、独自のツール、指示、ほかのエージェントへの引き継ぎとともに作るようエージェントを支援します。
create-skill
5.8k有効な名前、明確な発動の説明、規格に従うSKILL.mdファイルを持つ、新しいエージェントのスキルを作るようエージェントを支援します。
csharp-scripts
5.8k.NETのコマンドラインツールを使って、完全なプロジェクトを作らずに、小さなC#のプログラムを一つのファイルとして実行するようエージェントを支援します。
dotnet-pinvoke
5.8k署名、文字列の扱い、メモリ、安全なハンドルを含めて、ネイティブのC言語またはC++のライブラリを.NETから正しく呼び出すようエージェントを支援します。
似ているスキル
openclaw-update
394k既存のOpenClaw Gatewayを更新するようエージェントを支援します。インストール方法に合った更新方法を選び、セッションを動かし続けます。
diagnose-gateway
394k設定、チャンネル、ポートを確認して、OpenClaw Gatewayが失敗している理由を、何も変更せずに突き止めるようエージェントを支援します。
crabbox-apps
394k一時的なクラウドマシン上でアプリを開いて実行し、そのビューをチャットのサイドパネルに表示するようエージェントを支援します。