Jaa


Not the whole solution

A common misconception I hear a lot is that MSBuild knows how to build Visual Studio solutions. Technically this is not true, while in earnest it is true.

MSBuild understands enough about solution files to translate them into MSBuild project files. When MSBuild is launch, it checks the extension of the project it has been asked to build. If it sees that the file you are building has the extension ".sln", it runs a conversion on that file to create a ".metaproj" file. This metaproj is really just a translation of the solution file into MSBuild project file format. Note that you normally never see this file, as it is only generated in memory.

If you want to take a look at the gory details inside the metaproj, you can set the environment variable "MSBuildEmitSolution" to "1" and MSBuild will write the file out with the name "{solutionname}.sln.metaproj".

SET MSBuildEmitSolution=1

Once this is set, just run you build as normal to generate the metaproj file.

One thing to note is that since MSBuild is translating the solution file into a project file, there are things that may not be translated correctly. There are also things that simply may not be definable in the MSBuild language. One such beast is the set of solution dependencies. I typically recommend that users steer clear of these, and instead opt for P2P (or project to project) references. But, that is a topic for another article.

Comments

  • Anonymous
    May 19, 2011
    Thanks, Chuck. I always wondered how MSBuild handled building solutions. The best I'd heard before was that it didn't really but sort of did, which always confused me. It's good to know the under-the-hood conversion is going on.