Guides changes to MSBuild binary log infrastructure. Consult when modifying BinaryLogger or BinaryLogReplayEventSource, adding new BuildEventArgs types, changing event serialization/deserialization, modifying ProjectImportsCollector, adjusting message importance levels, or making changes that affect .binlog content. Also applies when verifying that behavioral changes are properly reflected in binary log output.
The binary log (.binlog) is MSBuild's primary diagnostic format and source of truth for build analysis. It captures the complete build event stream with full fidelity. Format changes have strict compatibility requirements.
For general binary log usage, see Binary-Log.md.
Build Engine
→ BuildEventArgs (structured events)
→ BinaryLogger (serializes to .binlog)
→ ProjectImportsCollector (embeds project/targets files)
Replay:
.binlog file
→ BinaryLogReplayEventSource (deserializes)
→ Any ILogger (console, structured log viewer, analyzers)
Key source files:
src/Build/Logging/BinaryLogger/BinaryLogger.cs — the logger itselfsrc/Framework/BuildEventArgs.cs — base class for all build eventssrc/Build/Logging/BinaryLogger/ProjectImportsCollector.cs — captures imported filesWhen adding a new BuildEventArgs subclass:
BuildMessageEventArgs, BuildWarningEventArgs, etc.)WriteToStream and CreateFromStream methods// Pattern for backward-compatible field addition
if (logVersion >= newFieldVersion)
{
writer.Write(newField);
}
// Reading with backward compatibility
if (logVersion >= newFieldVersion)
{
newField = reader.ReadString();
}
else
{
newField = defaultValue;
}
Importance controls what appears in console output, but everything goes to binlog regardless of importance.
| Level | Use For | Console Verbosity |
|---|---|---|
High | Critical user-facing information | Minimal and above |
Normal | Standard build progress | Normal and above |
Low | Detailed diagnostic information | Detailed and above |
Diagnostic | Internal debugging | Diagnostic only |
Normal for user-relevant informationLow for information useful when debugging but noisy in normal buildsHigh is reserved for important warnings/status — use sparinglyLow insteadThe ProjectImportsCollector embeds all imported .props, .targets, and project files into the binlog. This enables the "preprocessed view" in log viewers.
MSBUILDLOGIMPORTS=1 (or the /bl switch) enables import collectionWhen modifying MSBuild behavior, verify binlog impact:
| Change Type | Binlog Consideration |
|---|---|
| New property set during evaluation | Appears in PropertyInitialValue or PropertyReassignment events |
| New target added | Produces TargetStarted/TargetFinished events |
| Changed task behavior | Task output items/properties captured in TaskFinished |
| New warning/error | Captured as BuildWarningEventArgs/BuildErrorEventArgs |
| Modified import chain | Changes which files ProjectImportsCollector captures |
BinaryLogReplayEventSource in tests to verify binlog content programmaticallyWriteToStream/CreateFromStream implementations