Exploring a MSBuild binary log using the binary log viewer

 
 
  • Gérald Barré

Following my previous post about ILRepack, some people asked me where the MSBuild property ReferencePathWithRefAssemblies comes from. Is there documentation, or a way to find properties like this one? The MSBuild documentation is very useful for understanding how it works and its key concepts. However, it cannot cover all properties, since they depend on the project type and the targets that run. The best way to find properties is to look at the build log. Text logs are hard to read and don't show all the information needed to investigate what happened during a build. Since MSBuild 15.3, you can output a binary log that can be opened with the MSBuild Binary and Structured Log Viewer.

The binary log is a detailed record of the build process. It can be used to reconstruct text logs and analyzed by other tools. A binary log is usually 10-20x smaller than the most detailed text diagnostic-level log, yet it contains more information. By default, the binary logger collects the source text of project files, including all imported projects and target files encountered during the build.

Let's see how to generate a binary log and use the tool to find what you want!

#Generating a binary log using the command line

If you are using dotnet CLI, you can use the /bl argument to generate a binary log. This works for any command that uses MSBuild under the hood.

Shell
dotnet build /bl

If you use the msbuild CLI, follow these steps:

  1. Open the console with MSBuild in the path:

    Open developer prompt for Visual StudioOpen developer prompt for Visual Studio

  2. Run msbuild with /bl flag to generate the binary log:

    Shell
    msbuild solution.sln /bl

It outputs a file named msbuild.binlog:

Generated binlog fileGenerated binlog file

#Generating a binary log using Visual Studio

  1. Install the Visual Studio extension (VS2017 / VS2019): Project System Tools

  2. Install the Visual Studio extension (VS2022): Project System Tools

  3. Open the tool window under View > Other Windows > Build Logging

  4. Click the button Start logging builds

    Start logging builds in Visual StudioStart logging builds in Visual Studio

  5. Open the log

    Open binlogs created while building projects in Visual StudioOpen binlogs created while building projects in Visual Studio

#Inspecting a binary log

Install MSBuild Binary and Structured Log Viewer, and then open the file in the tool.

The tool lets you view the list of build steps along with the input and output parameters of each target. You can also view the XML code of the project to see where a target is defined.

MSBuild Binary and Structured Log ViewerMSBuild Binary and Structured Log Viewer

You can also search across the entire log:

Search specific data in the binary logSearch specific data in the binary log

This tool helps you understand MSBuild and discover useful data for writing your build scripts. It's a must-have in your toolbox.

#Additional resources

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?