5 Tips for Getting Starting with MSBuild for CruiseControl

I've been digging into MSBuild and its integration with CruiseControl.NET over the past week and have found some good references on the web. The MSDN documentation being the best I've found so far. I haven't found any "Best Practices" per se so am taking the liberty to start some of what I think make sense to me. Here are five tips to help get you started, however, I would definitely recommend taking a look at these links as well as the MSDN documentation.

Create a Separate Project File
Leave your solution and .*proj files untouched and create a new .proj file for you continuous integration build process. This will keep these generated files 100% generated. Furthermore, I believe this gives you more control in your build script development.

Start Simple
Don't try to construct the end-all-be-all build script in the first pass. Do just enough and nothing more. Like cooking, it's easier to add ingredients than make corrections later.

Execute Locally Before Deploying
Open up an SDK command prompt:

C:WINDOWSsystem32cmd.exe /k "C:Program FilesMicrosoft Visual Studio 8SDKv2.0Binsdkvars.bat"

Then change paths to your build file and execute the MSBuild.exe command in this console as you write your build script. This will allow for a much quicker write-save-test cycle than if you were to write-save-deploy-test on the CruiseControl server.

Write a Meta Build Script First
Before getting started on your first build script, decide what you want to do and write out the steps. This will give you a point of reference should you end up too far down some path along the way so you can pull back out and stay focused on what you are trying to accomplish. There are many different options and ways to do things with MSBuild and this is easy to do, especially when starting out. A typical meta build script might look like:

1. Compile Solution
2. Copy all compilation output to a common output directory
3. Archive this output to a single zip
4. Create a new directory with the build number on a network share intended for hosting build results.
5. Move this archive to the new directory.

Separate Common Tasks into Targets
As you script out the necessary tasks to accomplish your Meta Build Script goals, you'll likely notice common task functionality (Copying Output and Creating an Archive, for example could be a single target). Pull these out and parameterize them with the use of properties and put them in there own common *.targets file. The format of this file is simply:


This will give you the ability to reuse much of your work in other build scripts for different solutions/projects.

Tags: msbuild, ccnet, cruisecontrol, continuous integration