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 a documentation, or something to find properties like this one? The documentation of MSBuild is very useful to understand how it works and the key concepts. However, they cannot document all the properties because they depend of the kind of project you build and the targets that run. The solution to find properties is to look at the log of the build. The textual log is hard to read and doesn'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 by MSBuild Binary and Structured Log Viewer.
The binary log is a detailed description of the build process that can later be used to reconstruct text logs and used by other analysis tools. A binary log is usually 10-20x smaller than the most detailed text diagnostic-level log, but it contains more information. The binary logger by default 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
Open the console with MSBuild in the path:
/blflag to generate the binary log:Shell
msbuild solution.sln /bl
It outputs a file named
#Generating a binary log using Visual Studio
Install the Visual Studio extension (VS2017 / VS2019): Project System Tools
Install the Visual Studio extension (VS2022): Project System Tools
Open the tool window under
View > Other Windows > Build Logging
Click the button
Start logging builds
Open the log
Open 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 allows you to view the list of steps of the build with the input and output parameters of each target. You can also view the XML code of the project to view where the target is defined.
MSBuild Binary and Structured Log Viewer
You can also search for something in all the log
Search specific data in the binary log
This tool allows you to understand MSBuild and find useful data to write your build script. It's a must-have in your toolbox.
Do you have a question or a suggestion about this post? Contact me!