Skip to content
Kirill Osenkov edited this page Nov 18, 2021 · 6 revisions

Indexing MSBuild .binlog files

An MSBuild .binlog is a detailed binary log of everything that happened during the build. See here for more information: https://msbuildlog.com

A new feature in SourceBrowser is indexing binlogs. Here's the primary commit https://github.com/KirillOsenkov/SourceBrowser/commit/b79ff9c

How to use the CompilerInvocations API: https://github.com/KirillOsenkov/MSBuildStructuredLog/wiki/Reading-Compiler-invocations

Here's how it's used: https://github.com/KirillOsenkov/SourceBrowser/blob/6e4900c1087e66523834541cf5e6db3af8cb4d18/src/HtmlGenerator/Program.cs#L156-L165

Instead of passing an .sln file to HtmlGenerator, you can now pass a .binlog file instead. Instead of loading the solution into MSBuildWorkspace and running a design-time build for each project to populate the Roslyn workspace, it parses the binlog for all Csc task invocations, reads the command line arguments and populates the Roslyn workspace from those.

As a huge benefit of this approach, MSBuild isn't used by indexing at all. All the information we need is extracted from the .binlog after a given repo builds, all we need is the original source files used during the build in their original locations, and the binlog. So no SDK resolution, none of that stuff. And we get absolutely correct contents, exactly what the compiler saw, guaranteed by construction. This approach is more likely to work for highly customized builds where the classic SourceBrowser didn't work properly because of MSBuildWorkspace limitations.

This feature is first introduced in NuGet 1.0.27: https://www.nuget.org/packages/SourceBrowser/1.0.27

Clone this wiki locally