Embedding additional files in an MSBuild binary log file

 
 
  • Gérald Barré

The MSBuild binary logger enables in-depth investigation of build issues. It records all events that occur during a build and can be replayed to reproduce it. I've covered 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), which is useful for investigating build issues. It is also possible to embed additional files in the binlog. This is helpful when you generate files dynamically during the build and want to preserve a copy for later investigation.

Embedding additional files in the binlog is straightforward. Add the following item to your project file:

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

Then build the project with the binary logger:

Shell
dotnet build /bl:output.binlog

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?