Verbosity & Binary Logs
When a build misbehaves you need to see what MSBuild did: which targets ran or were skipped, which values properties had, the exact compiler command line. MSBuild can tell you everything, at five levels of detail, and it can record everything once in a binary log that you analyse afterwards.
The five verbosity levels
-v: (or -verbosity:) takes q[uiet], m[inimal], n[ormal], d[etailed] and diag[nostic]. dotnet build defaults to minimal. The size of the log for the same tiny project:
mkdir q && cd q
cat > q.csproj <<'XML'
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
</Project>
XML
echo 'public class Q { }' > Q.cs
for v in quiet minimal normal; do
rm -rf bin obj
echo "$v: $(dotnet build -v:$v | wc -l) lines"
done
rm -rf bin obj
dotnet build -v:diag > diag.log
[ "$(wc -l < diag.log)" -gt 50000 ] && echo "diagnostic: more than 50000 lines"quiet: 6 lines
minimal: 9 lines
normal: 61 lines
diagnostic: more than 50000 lines
| Level | Shows | Use it for |
|---|---|---|
quiet |
errors, warnings, summary | scripts |
minimal |
plus one line per project output | everyday builds |
normal |
plus every target name, skipped targets with the reason, tool command lines, messages with normal importance | "why did this rebuild?" |
detailed |
plus task parameters, item and property changes | debugging your own targets |
diagnostic |
plus the environment, all initial properties and items, every property reassignment with file and line | "where does this value come from?" |
Excerpts worth knowing
Normal verbosity prints the exact command each tool ran. For the C# compiler that's one long line; here are its first options:
mkdir q && cd q
cat > q.csproj <<'XML'
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
</Project>
XML
echo 'public class Q { }' > Q.cs
dotnet build -v:n | grep 'Roslyn/bincore/csc /noconfig' | tr ' ' '\n' | grep -E '^/(target|debug|optimize|deterministic|define|langversion|nullable|out|refout)[:+-]'
dotnet build -v:diag | grep -m2 'Property reassignment: \$(AssemblySearchPaths)' | sed 's|/usr/share/dotnet/sdk/10.0.402/Sdks/Microsoft.NET.Sdk/targets/|<sdk>/|g; s/^ *//'/define:TRACE;DEBUG;NET;NET10_0;NETCOREAPP;NET5_0_OR_GREATER;NET6_0_OR_GREATER;NET7_0_OR_GREATER;NET8_0_OR_GREATER;NET9_0_OR_GREATER;NET10_0_OR_GREATER;NETCOREAPP1_0_OR_GREATER;NETCOREAPP1_1_OR_GREATER;NETCOREAPP2_0_OR_GREATER;NETCOREAPP2_1_OR_GREATER;NETCOREAPP2_2_OR_GREATER;NETCOREAPP3_0_OR_GREATER;NETCOREAPP3_1_OR_GREATER
/debug+
/debug:portable
/optimize-
/out:obj/Debug/net10.0/q.dll
/refout:obj/Debug/net10.0/refint/q.dll
/target:library
/deterministic+
/langversion:14.0
<sdk>/Microsoft.NET.Sdk.props(90,5): message : Property reassignment: $(AssemblySearchPaths)="{CandidateAssemblyFiles};{HintPathFromItem}" (previous value: "{CandidateAssemblyFiles}") at <sdk>/Microsoft.NET.Sdk.props (90,5)
<sdk>/Microsoft.NET.Sdk.props(91,5): message : Property reassignment: $(AssemblySearchPaths)="{CandidateAssemblyFiles};{HintPathFromItem};{TargetFrameworkDirectory}" (previous value: "{CandidateAssemblyFiles};{HintPathFromItem}") at <sdk>/Microsoft.NET.Sdk.props (91,5)
- The compiler switches (
/optimize-,/define:TRACE;DEBUG;NET;…,/deterministic+,/refout:for the reference assembly) are where the properties of the previous lessons finally end up. When a property "has no effect", check whether it reaches this command line. - At diagnostic verbosity, every property reassignment is logged with the old value, the new value and the file and line that changed it. It answers "who overwrote my property?" without reading seventeen thousand lines of
-ppoutput.
Binary logs
Text logs at diagnostic verbosity are huge, slow to write and still lose structure. A binary log records the complete build (every evaluation, property, item, target, task, message and the content of every imported project file) in a compact file:
mkdir q && cd q
cat > q.csproj <<'XML'
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
</Project>
XML
echo 'public class Q { }' > Q.cs
dotnet build -bl -v:q > /dev/null
ls *.binlog
dotnet build -bl:logs/release.binlog -c Release -v:q > /dev/null
ls logs
echo "--- replaying the binlog through the console logger"
dotnet msbuild logs/release.binlog -v:mmsbuild.binlog
release.binlog
--- replaying the binlog through the console logger
Determining projects to restore...
All projects are up-to-date for restore.
q -> /home/learner/q/bin/Release/net10.0/q.dll
-blwritesmsbuild.binlogin the current folder;-bl:pathpicks a name. It works withdotnet build,test,pack,publishandmsbuild.- Recording costs little, so a common CI practice is to always build with
-bland upload the file as an artifact when the build fails. - Replaying a binlog with
dotnet msbuild file.binlogfeeds it to the console logger at any verbosity, without building again. Record once, then look at it asminimal,normalordiaglater.
The real power is the MSBuild Structured Log Viewer (Windows/macOS/Linux app, and a web version at live.msbuildlog.com that runs entirely in the browser), described in the toolkit lesson. It shows the build as a tree, searches every property and item, explains why each target ran or was skipped, and shows timing per target and task.
Warning: A binlog contains the environment variables and all imported files of the build. If your CI injects secrets as environment variables or writes them into a
.propsfile, they end up in the log.-bl:LogFile=build.binlog;ProjectImports=Noneleaves the embedded project files out, but properties derived from environment variables are still recorded. Treat binlogs from CI as sensitive and don't attach them to public issues without checking.
The terminal logger
On an interactive terminal, dotnet build in .NET 9 and later uses the terminal logger: a live view of running projects that collapses to a short summary. It's off in this course's sessions (MSBUILDTERMINALLOGGER=off) because it redraws lines. Control it with -tl:on, -tl:off or -tl:auto; CI systems that aren't terminals get the classic console logger automatically.
Test yourself
Which verbosity is the lowest one that prints the full C# compiler command line?
- quiet
- minimal
- normal
- diagnostic only
What does dotnet msbuild build.binlog -v:diag do?
- Rebuilds the project with diagnostic logging
- Replays the recorded build through the console logger at diagnostic verbosity, without building
- Converts the binlog to XML
- Uploads the log
Why should binlogs from CI be handled with care?
- They are executable
- They include environment variables and imported files, which may contain secrets
- They can only be opened once
- They modify the build cache