Embedding additional files in an MSBuild binary log file
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:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<!-- Embed all txt files in the binlog -->
<EmbedInBinlog Include="**/*.txt" />
</ItemGroup>
</Project>
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!