Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)5.8k · #14602

incremental-build

Skill này làm gì

Skill này tìm vì sao MSBuild build lại các target ở lần chạy thứ hai khi không có gì thay đổi, rồi sửa thiết lập. Skill dành cho lập trình viên có build không thay đổi chậm như build đầy đủ.

Khi nào nên dùng

  • ✓Khi một build chạy lại mọi thứ dù không có gì thay đổi.
  • ✓Khi một target tự định nghĩa chạy mỗi lần thay vì bị bỏ qua.
  • ✓Khi build chậm ở các lần chạy lặp lại nhưng không chậm ở lần đầu.

Liên kết skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/incremental-build/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/incremental-build/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tôi không thay đổi gì, nhưng build .NET vẫn build lại toàn bộ project. Tìm vì sao và sửa nó.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent so sánh timestamp đầu vào và đầu ra của các target chậm, tìm đầu vào hoặc đầu ra bị thiếu hoặc file được ghi ngoài output đã theo dõi, rồi đề xuất bản sửa. Skill kiểm tra bằng hai build giống nhau.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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 Inputs and Outputs attributes: MSBuild compares the timestamps of all files listed in Inputs against all files listed in Outputs. 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)

  1. Missing Inputs/Outputs on custom targets — Without both attributes, the target always runs. This is the single most common cause of unnecessary rebuilds.

  2. 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.

  3. 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.

  4. Missing FileWrites registration — Files created during the build but not registered in the FileWrites item group won't be cleaned by dotnet clean. Over time, stale files can confuse incremental checks.

  5. Glob changes — When you add or remove source files, the item set (e.g., @(Compile)) changes. Since these items feed into Inputs, the set of inputs changes and triggers a rebuild. This is expected behavior but can be surprising.

  6. Property changes — Properties that feed into Inputs or Outputs paths (e.g., $(Configuration), $(TargetFramework)) will cause rebuilds when changed. Switching between Debug and Release is a full rebuild by design.

  7. NuGet package updates — Changing a package version updates project.assets.json and potentially many resolved assembly paths. This changes the inputs to ResolveAssemblyReferences and CoreCompile, triggering a rebuild.

  8. 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:

  1. Actual timestamp comparison — name the newest resolved input and oldest resolved output, with their last-write times, and state which input is newer.
  2. **Output existence
Câu hỏi thường gặp

Build không thay đổi nghĩa là gì?

Đó là lần build thứ hai không có chỉnh sửa, và các target của nó nên được bỏ qua để hoàn tất nhanh.

Skill có thay đổi file mà không hỏi không?

Skill chẩn đoán trước, và chỉ sửa khi bạn yêu cầu.

Vì sao giá trị biến động gây build lại?

Các giá trị như timestamp hoặc GUID ngẫu nhiên trong đường dẫn output thay đổi mỗi lần build, nên MSBuild coi output là mới.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
5.8k
Vị trí xếp hạng
#14602
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự