Sunday, August 01, 2010

MSBuild: Basics

I have spent a good deal of time with MSBuild scripts the past couple of years as I have worked on various projects. As I have attempted to make these scripts bend to my wishes I have gradually improved the sample MSBuild script I carry along to each new project. In this series I will cover various ways to use MSBuild and include some tips on what you can do to make your scripts work better for you. But first, what is MSBuild?
The MSBuild utility was introduced with .NET 2.0 and is available with the runtime even if Visual Studio is not installed. It allows for build automation of most Visual Studio project types. Previously, a utility called NAnt was used as a build tool for .NET 1.1 which is modeled after Ant, a tool to build Java projects. The introduction of MSBuild as an official utility was very welcome among the development community as it provides close integration with the existing project and solution files created by Visual Studio. This close integration cuts down on the amount of detail necessary for the build scripts.

In some ways MSBuild is quite similar to the NAnt and Ant predecessors, such that the scripts are XML files representing Targets of execution with various Tasks within those Targets. And between Targets a dependency tree can be created to ensure certain Targets are completed before the called Target. That is all quite similar to NAnt and Ant. However, the way properties and lists are defined is quite different.
Read more: Brennan’s Blog Basics, Item GroupDependencies, Configuration, Web Deployments, Unit Test, Packaging