Binlog Generation

作者 dotnet0608d8924cd3MIT5.5K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Generate MSBuild binary logs (binlogs) for build diagnostics and analysis. USE FOR: adding /bl:{} to any dotnet build, test, pack, publish, or restore command to capture a full build execution trace, prerequisite for binlog-failure-analysis and build-perf-diagnostics skills, enabling post-build investigation of errors or performance. Requires MSBuild 17.8+ / .NET 8 SDK+ for {} placeholder; PowerShell must quote the complete switch as '-bl:{}'. DO NOT USE FOR: non-MSBuild build systems (npm, Maven, CMake), analyzing an existing binlog (use binlog-failure-analysis instead).

AI 產生的概覽

為 .NET 建置命令加上 MSBuild 二進位記錄開關,以便擷取建置過程供後續分析。

功能
此技能指示代理在 MSBuild 相關命令(例如 dotnet build、test、pack、publish、restore 與 msbuild)後附加 /bl:{} 開關。它說明 {} 佔位符會為每次呼叫產生唯一的 binlog 檔名、如何在 PowerShell 中引用該開關、如何確認已產生 .binlog 檔案,以及需要指定檔名時該如何選擇。它也說明使用 git clean 時要排除 binlog 檔案,以保留建置歷史。
適用情境
在執行任何 MSBuild 或 dotnet 的 build、test、pack、publish、restore 命令,並希望保留完整執行記錄時使用。它也是分析建置失敗或排查建置效能之前的準備步驟。
執行需求
需要以 MSBuild 為基礎的工具鏈,例如 .NET SDK;使用 {} 佔位符需要 MSBuild 17.8+ / .NET 8 SDK 或更新版本。不附帶指令碼,僅為說明性內容。

Generate Binary Logs

Pass the /bl switch when running any MSBuild-based command. This is a non-negotiable requirement for all .NET builds.

Commands That Require /bl

You MUST add the /bl:{} flag to:

  • dotnet build
  • dotnet test
  • dotnet pack
  • dotnet publish
  • dotnet restore
  • msbuild or msbuild.exe
  • Any other command that invokes MSBuild

Preferred: Use {} for Automatic Unique Names

Note: The {} placeholder requires MSBuild 17.8+ / .NET 8 SDK or later.

The {} placeholder in the binlog filename is replaced by MSBuild with a unique identifier, guaranteeing no two builds ever overwrite each other — without needing to track or check existing files.

bash
# Every invocation produces a distinct file automaticallydotnet build /bl:{}dotnet test /bl:{}dotnet build --configuration Release /bl:{}

PowerShell requires quoting the complete switch:

powershell
# Keep the literal {} placeholder in one argumentdotnet build '-bl:{}'dotnet test '-bl:{}'

Why This Matters

  1. Unique names prevent overwrites - You can always go back and analyze previous builds
  2. Failure analysis - When a build fails, the binlog is already there for immediate analysis
  3. Comparison - You can compare builds before and after changes
  4. No re-running builds - You never need to re-run a failed build just to generate a binlog

Examples

bash
# ✅ CORRECT - {} generates a unique name automatically (bash/cmd)dotnet build /bl:{}dotnet test /bl:{}
# ✅ CORRECT - quote the complete PowerShell argumentdotnet build '-bl:{}'dotnet test '-bl:{}'
# ❌ WRONG - Missing /bl flag entirelydotnet builddotnet test
# ❌ WRONG - No filename (overwrites the same msbuild.binlog every time)dotnet build /bldotnet build /bl

One build = one binlog

Add /bl:{} to every MSBuild invocation separately — never reuse a name and never rely on bare /bl:

  • Building several configurations, projects, or retrying a failed build? Each command still gets its own /bl:{} so the logs never overwrite each other.
bash
dotnet build -c Debug   /bl:{}   # unique filedotnet build -c Release /bl:{}   # another unique file

Verify the binlog exists

After the build, confirm a .binlog was actually produced before moving on to analysis — a build that fails before MSBuild starts (e.g. a bad argument) writes no binlog:

bash
ls -1 *.binlog       # bashdir /b *.binlog      # Windows cmd
powershell
Get-ChildItem *.binlog   # PowerShell

Note the resulting path so binlog-failure-analysis or build-perf-diagnostics can consume it.

When a Specific Filename Is Required

If the binlog filename needs to be known upfront (e.g., for CI artifact upload), or if {} is not available in the installed MSBuild version, pick a name that won't collide with existing files:

  1. Check for existing *.binlog files in the directory
  2. Choose a name not already taken (e.g., by incrementing a counter from the highest existing number)
bash
# Example: directory contains 3.binlog — use 4.binlogdotnet build /bl:4.binlog

Cleaning the Repository

When cleaning the repository with git clean, always exclude binlog files to preserve your build history:

bash
# ✅ CORRECT - Exclude binlog files from cleaninggit clean -fdx -e "*.binlog"
# ❌ WRONG - This deletes binlog files (they're usually in .gitignore)git clean -fdx

This is especially important when iterating on build fixes - you need the binlogs to analyze what changed between builds.

來源與署名

來源:dotnet/skills位於plugins/dotnet-msbuild/skills/binlog-generation提交0608d89

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架