MSBuild binary logs (binlogs) are a powerful tool for diagnosing build issues. If you're not familiar with binlogs, Exploring a MSBuild binary log using the binary log viewer is a good starting point; Stop using diagnostic verbosity in MSBuild explains why binlogs are a better alternative to diagnostic verbosity.
By default, binlogs capture extensive build information, but you can get even more detail about property changes by enabling property tracking. This feature helps you understand when and where properties are set, reassigned, or read during the build process.
#Enabling property tracking
To enable property tracking, set the MSBuildLogPropertyTracking environment variable before running your build. This variable accepts a numeric value that controls which events are tracked:
| Value | Event Type | Description |
|---|
| 0 | None | Disables explicit property tracking |
| 1 | PropertyReassignment | Tracks when a property value is changed |
| 2 | PropertyInitialValueSet | Tracks when a property is first initialized |
| 4 | EnvironmentVariableRead | Tracks when environment variables are read |
| 8 | UninitializedPropertyRead | Tracks when reading a property that hasn't been initialized |
These values are bit flags, so you can combine them. For example, to enable all tracking events, use the value 15 (1 + 2 + 4 + 8):
Property tracking covers the following scenarios:
- Properties set via command-line arguments (e.g. using
/p: switches) - Properties derived from environment variables
- Properties set as target outputs
- Properties set as task outputs
- Properties defined in XML during evaluation (with exact location information including line and column)
#Viewing the tracked properties
Once you build with property tracking enabled, you can open the binlog file using the MSBuild Structured Log Viewer. The log will contain additional nodes showing property initialization, reassignment, and reads.
Property Initialized node
#Additional resources
If you want to learn more about MSBuild binlogs, these related posts are worth reading:
Do you have a question or a suggestion about this post? Contact me!