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, 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:

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

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

Follow me:
Enjoy this blog?