Getting more information in MSBuild binlogs with property tracking

 
 
  • Gérald Barré

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:

ValueEvent TypeDescription
0NoneDisables explicit property tracking
1PropertyReassignmentTracks when a property value is changed
2PropertyInitialValueSetTracks when a property is first initialized
4EnvironmentVariableReadTracks when environment variables are read
8UninitializedPropertyReadTracks 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):

  • PowerShell:

    PowerShell
    $env:MSBuildLogPropertyTracking = 15
    dotnet build -bl
  • Bash:

    Shell
    export MSBuildLogPropertyTracking=15
    dotnet build -bl

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 nodeProperty 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!

Follow me:
Enjoy this blog?