binlog-generation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGenerate Binary Logs
生成二进制日志
Pass the switch when running any MSBuild-based command. This is a non-negotiable requirement for all .NET builds.
/bl**在运行任何基于MSBuild的命令时,必须传递参数。**这是所有.NET构建的硬性要求。
/blCommands That Require /bl
需要使用/bl的命令
You MUST add the flag to:
/bl:{}dotnet builddotnet testdotnet packdotnet publishdotnet restore- or
msbuildmsbuild.exe - Any other command that invokes MSBuild
你必须为以下命令添加参数:
/bl:{}dotnet builddotnet testdotnet packdotnet publishdotnet restore- 或
msbuildmsbuild.exe - 任何其他调用MSBuild的命令
Preferred: Use {}
for Automatic Unique Names
{}推荐用法:使用{}
自动生成唯一名称
{}Note: Theplaceholder 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
undefined注意:占位符需要MSBuild 17.8+ / .NET 8 SDK或更高版本。{}
binlog文件名中的占位符会被MSBuild替换为唯一标识符,确保两次构建的日志不会互相覆盖——无需手动跟踪或检查现有文件。
{}bash
undefinedEvery invocation produces a distinct file automatically
每次执行都会自动生成一个唯一的文件
dotnet build /bl:{}
dotnet test /bl:{}
dotnet build --configuration Release /bl:{}
**PowerShell requires escaping the braces:**
```powershelldotnet build /bl:{}
dotnet test /bl:{}
dotnet build --configuration Release /bl:{}
**PowerShell中需要对大括号进行转义:**
```powershellPowerShell: escape { } as {{ }}
PowerShell:将{ }转义为{{ }}
dotnet build -bl:{{}}
dotnet test -bl:{{}}
undefineddotnet build -bl:{{}}
dotnet test -bl:{{}}
undefinedWhy This Matters
为什么这很重要
- Unique names prevent overwrites - You can always go back and analyze previous builds
- Failure analysis - When a build fails, the binlog is already there for immediate analysis
- Comparison - You can compare builds before and after changes
- No re-running builds - You never need to re-run a failed build just to generate a binlog
- 唯一名称避免覆盖 - 你可以随时回溯并分析之前的构建记录
- 故障排查 - 当构建失败时,binlog已准备好供立即分析
- 对比分析 - 你可以对比变更前后的构建情况
- 无需重新构建 - 永远不需要为了生成binlog而重新运行失败的构建
Examples
示例
bash
undefinedbash
undefined✅ CORRECT - {} generates a unique name automatically (bash/cmd)
✅ 正确用法 - {}会自动生成唯一名称(bash/cmd环境)
dotnet build /bl:{}
dotnet test /bl:{}
dotnet build /bl:{}
dotnet test /bl:{}
✅ CORRECT - PowerShell escaping
✅ 正确用法 - PowerShell中的转义写法
dotnet build -bl:{{}}
dotnet test -bl:{{}}
dotnet build -bl:{{}}
dotnet test -bl:{{}}
❌ WRONG - Missing /bl flag entirely
❌ 错误用法 - 完全缺少/bl参数
dotnet build
dotnet test
dotnet build
dotnet test
❌ WRONG - No filename (overwrites the same msbuild.binlog every time)
❌ 错误用法 - 未指定文件名(每次构建都会覆盖同一个msbuild.binlog文件)
dotnet build /bl
dotnet build /bl
undefineddotnet build /bl
dotnet build /bl
undefinedWhen 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:
{}- Check for existing files in the directory
*.binlog - Choose a name not already taken (e.g., by incrementing a counter from the highest existing number)
bash
undefined如果需要预先确定binlog文件名(例如用于CI制品上传),或者当前安装的MSBuild版本不支持占位符,请选择一个不会与现有文件冲突的名称:
{}- 检查目录中已有的文件
*.binlog - 选择一个未被使用的名称(例如,在现有最高编号基础上加1)
bash
undefinedExample: directory contains 3.binlog — use 4.binlog
示例:目录中已有3.binlog —— 使用4.binlog
dotnet build /bl:4.binlog
undefineddotnet build /bl:4.binlog
undefinedCleaning the Repository
清理仓库
When cleaning the repository with , always exclude binlog files to preserve your build history:
git cleanbash
undefined使用清理仓库时,务必排除binlog文件以保留构建历史:
git cleanbash
undefined✅ CORRECT - Exclude binlog files from cleaning
✅ 正确用法 - 清理时排除binlog文件
git clean -fdx -e "*.binlog"
git clean -fdx -e "*.binlog"
❌ WRONG - This deletes binlog files (they're usually in .gitignore)
❌ 错误用法 - 会删除binlog文件(它们通常已被加入.gitignore)
git clean -fdx
This is especially important when iterating on build fixes - you need the binlogs to analyze what changed between builds.git clean -fdx
这在迭代修复构建问题时尤为重要——你需要binlog来分析不同构建之间的变化。