Visual Studio – Why Use MSBuild Instead of Solution Files?

msbuildprojects-and-solutionsvisual studio

We're using TeamCity for continuous integration and it's building our releases via the solution file (.sln). I've used Makefiles in the past for various systems but never msbuild (which I've heard is sorta like Makefiles + XML mashup). I've seen many posts on how to use msbuild directly instead of the solution files but I don't see a very clear answer on why to do it.

So, why should we bother migrating from solution files to an MSBuild 'makefile'? We do have a a couple of releases that differ by a #define (featurized builds) but for the most part everything works.

The bigger concern is that now we'd have to maintain two systems when adding projects/source code.

UPDATE:

Can folks shed light on the lifecycle and interplay of the following three components?

  1. The Visual Studio .sln file
  2. The many project level .csproj files (which I understand an "sub" msbuild scripts)
  3. The custom msbuild script

Is it safe to say that the .sln and .csproj are consumed/maintained as usual from within the Visual Studio IDE GUI while the custom msbuild script is hand-written and usually consumes the already existing individual .csproj "as-is"? That's one way I can see reduce overlap/duplicate in maintenance…

Would appreciate some light on this from other folks' operational experience

Best Answer

First point of fact is that the solution file pretty much magically becomes a MSBuild file when MSBuild executes it -- which is what happens when you build the solution in visual studio. In addition, all those project files are just msbuild files managed by visual studio. In fact, the project files handle most of the real dirty work here no matter if you are building from solutions or building from a custom msbuild script.

We also use TeamCity to build and publish applications and we will typically end up with custom msbuild scripts for most projects. The role these scripts play -- which isn't really easy with a solution file -- is packaging the project for deployment or distribution. Typically these scripts handle some more operational aspects of things -- like building the web project to a particular folder or copying in the running configurations as opposed to the development configurations. The heavy lifting tends to be handled in the project files themselves -- the build script just references those, we don't try and recreate that wheel. Overall it works great and it isn't really much duplicated code. Typically once we get the build scripts up we rarely have to touch them until there are massive changes in a project mandating massively changing the build.

Related Topic