I recently learned all about how MSBuild logging works and was surprised at how powerful it is. I was also disappointed how little information there is on the topic (though the docs are quite good). In this post I'll discuss what MSBuild logging is and how you can write your own cross-platform logger that can be plugged into any build process.
The MSBuild APIs are now on NuGet and target
netstandard which is awesome, but unfortunately they won't work out of the box with certain platform and project type combinations. The reasons are complex, but basically come down to MSBuild not being a self contained project system. In order for the MSBuild APIs to work with certain project types like SDK-style, MSBuild needs to be told where to find the extra stuff that it needs (like the SDK targets) before it can process the project file. Additionally, if all you care about is metadata like the resolved source files, references, and project properties then you don't actually have to run the compiler. Once you can open the project in MSBuild you can tell it to perform a design-time build which gives you this information without the performance hit of actually compiling the project. Doing so can be valuable for a number of different use cases including code generation, documentation engines, and build orchestration. This post explains some tricks for getting MSBuild to work for any project and then using it to get project metadata without triggering a compilation.