Monday, July 02, 2007

Structuring NAnt Buildfiles For CCNet builds.

I get all verklempt over automated builds. The usefulness of scripting your builds and running them on an automated system cannot be overstated. Period.

Preventing bloat and keeping your builds in sync with the code base is difficult if you don't keep them close. Typically code will be split into separate files to make it more maintainable, build files are no different. I've found that a single build file for anything but the simplest project can grow very unwieldy quickly but by keeping only one coordinating build file at the solution level and splitting the builds up by project, automated builds can be easier to implement and manage. Also, by keeping the files alongside the code they are the building the builds stay in sync with the code they are building.

For example, I have a solution containing 3 projects. One is an executable, two are libraries. The folder structure and the naming of the solutions typically follows the structure of the namespaces.

Let's work from a root folder named 'source' sitting on C:.


Inside of here I have a solution folder named FrogsBrain.MyFancyPants, the solution will match the name of the folder.


I'll go ahead and add my standard folder to hold my master build script.


The primary concern of this build file will be to call the project builds in the correct order and perform any global configuration for those projects.

Now I will build the project folders.


And this too will contain a folder for it's respective build file.


The pattern will be repeated for the other two projects.


VS.Net Solutions can hold items that are not inside a project. Unfortunately, whenever you just add a Solution Item, VS.Net will ignore the folder structure and link to the item directly underneath the solution name. To imitate your physical folder inside your solution, add a new Solution Folder and name it '_build' to match your physical folder, then add the master build file as a Solution Item inside that folder.

Now your VS.Net Solution will look like...


Now your build files will be added to source control and versioned alongside the code they are building. This will make executing automated builds easier because the location and naming of the build files will be standardized, making the process easier and more repeatable.

Submit this story to DotNetKicks