MSBuild binary logs (binlogs) are a powerful tool for diagnosing build issues. If you're not familiar with binlogs, check out my post Exploring a MSBuild binary log using the binary log viewer to get started, or Stop using diagnostic verbosity in MSBuild to understand why binlogs are better than diagnostic verbosity.
By default, binlogs capture a lot of information, but you can get even more details 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):
The feature tracks properties in the following scenarios:
- Properties set via command-line arguments (e.g. using
/p: switches) - Properties defined based on 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, check out these related posts:
Do you have a question or a suggestion about this post? Contact me!