Embedding additional files in an MSBuild binary log file

  • Gérald Barré

MSBuild binary logger allows us to investigate build issues in depth. It records all the events that occur during a build, and it can be replayed to reproduce the build. I've already written about this logger in previous posts: Exploring a MSBuild binary log using the binary log viewer, Detecting Double-Writes in MSBuild using the binlog.

By default, the binlog file contains the content of all MSBuild files (props, targets). This is useful to investigate build issues. But it is also possible to embed additional files in the binlog file. This could be useful if you generate a file dynamically during the build, and you want to keep a copy of this file for later investigation.

It's now simple to embed additional files in the binlog file. You just need to add the following item to your project file:

MyProject.csproj (csproj (MSBuild project file))
<Project Sdk="Microsoft.NET.Sdk">
    <!-- Embed all txt files in the binlog -->
    <EmbedInBinlog Include="**/*.txt" />

You can then build the project using the binary logger:

dotnet build /bl:output.binlog

You can open the generated binlog file using MSBuild Binary and Structured Log Viewer:

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

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub