Using CruiseControl.NET with MSBuild

Cover Image for Using CruiseControl.NET with MSBuild
Weijie Lin

Originated from Extreme programming, the concept of Continuous Integration has been gradually adopted to other traditional software development methodologies. I think it will bring tremendous value to our .NET based projects so I decided to set up the environment and give it a try.


CruiseControl.NET is one of the most commonly used Continuous Integration tools on the .NET platform. It works well with NAnt to build Visual Studio 2003 based projects, but as of NAnt 0.85-rc 4 there is no support for task for Visual Studio 2005 projects. As a result, NAnt can only compile Visual Studio 2005 solution on a per project basis. By default, unlike VS 2003, Visual Studio 2005 uses a new file structure based Web project, which doesn't have a project file. This imposes even more problems for NAnt to work with VS 2005 solutions.

Setting up CruiseControl.NET and NAnt to work with Visual Studio 2003 projects is relatively easy, so I will try to set up CruiseControl.NET to work with Visual Studio 2005 projects here. Since Visual Studio 2005 and .NET Framework 2.0, Microsoft introduced a new extensible, XML-based build engine named MSBuild. In fact, the solution files and project files in VS 2005 are all written in MSBuild format. So instead of using NAnt with CruiseControl.NET, we are able to leverage MSBuild for compiling VS 2005 based solutions.

Prepare to install

First make sure the project compiles with MSBuild, by checking out a fresh copy and navigate to the project root directory then issue "msbuild MyProject.sln"

Install CruiseControl.NET

Installing CruiseControl.NET is easy. Simple grab the installer from CruiseControl.NET at Thoughtworks. I also downloaded and installed CCTray. CCTray is used to view and control the build process from client side, it can be installed locally on the build server as well as remotely.

The approach

In this approach, I use CruiseControl.NET to run NAnt scripts which in turn use MSBuild for compiling the Visual Studio 2005 solution. MSBuild is more capable then just compiling, but I am more familiar with NAnt so it's easier for me to setup NAnt the way I wanted. Basically I use NAnt script to clean up directory, get source code, and call MSBuild executable to compile. I am sure CruiseControl.NET can employ MSBuild directly and MSBuild is able to do things like cleaning up the directory and getting the source code. But I won't get to that until I actually have time to learn MSBuild.

Files that will be edited/created are as follows:

  • NAnt.exe.config - NAnt config file (located in the NAnt bin directory)
  • ccnet.config - CruiseControl.NET config file (located in the CruiseControl.NET installation directory)
  • - NAnt build script (new file created in "C:\ProjectBuild\CruiseControl.NET\server
  • \MyProject\WorkingDirectory")

Configure CruiseControl.NET Add settings to ccnet.config file, add project section as follows

<project> <name>MyProject</name> <webURL>http://localhost/ccnet/ default.aspx?_action_ViewProjectReport=true& server=local&project=MyProject </webURL> <triggers> <intervalTrigger seconds="600" /> </triggers> <sourcecontrol type="vss"> <project>$/MyProjectRoot/MyProject</project> <username>MyUserName</username> <password>MyPassword</password> <ssdir>\\server\vss</ssdir> </sourcecontrol> <tasks> <nant> <executable>C:\ProjectBuild\nant-0.85-rc3\bin\nant.exe</executable> <baseDirectory>C:\ProjectBuild CruiseControl.NET\server\MyProject\WorkingDirectory</baseDirectory> <buildFile></buildFile> <targetList> <target>run</target> </targetList> <buildTimeoutSeconds>1200</buildTimeoutSeconds> </nant> </tasks> </project>

As aforementioned the configuration didn't use MSBuild directly, rather it relies on NAnt to define the build tasks.

Configure NAnt

NAnt config file

MSBuild does not come with a XML Logger by default, so I need to use an external logger to get this functionality. I download the dll from here. And then I move the ThoughtWorks.CruiseControl.MsBuild.dll file to "C:\ProjectBuild\CruiseControl.NET\Tools".

Add MSBuild property to properties section


<properties> <!--properties defined here are accessible to all build files --> <property name="msbuild.exe" value="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe" overwrite="false" /> <property name="msbuild.logger.class" value="ThoughtWorks.CruiseControl.MsBuild.XmlLogger" overwrite="false" /> <property name="msbuild.logger.assembly" value="C:\ProjectBuild\CruiseControl.NET Tools\ThoughtWorks.CruiseControl.MsBuild.dll" overwrite="false" /> </properties>

NAnt build file

Finally, this is my NAnt build file

<?xml version="1.0"?> <target name="clean"> <delete dir="Source" failonerror="false" /> <mkdir dir="Source" /> </target> <target name="get" depends="clean"> <vssget username="MyUserName" password="MyPassword" localpath="Source" recursive="true" replace="true" writable="false" dbpath="\\server\vss\srcsafe.ini" path="$/MyProjectRoot/MyProject" /> </target> <target name="build" depends="get"> <exec program="${msbuild.exe}"> <arg value="/logger:${msbuild.logger.class},${msbuild.logger.assembly}" /> <arg value="/target:Build" /> <arg value="/verbosity:minimal" /> <arg value="/noconsolelogger" /> <arg value="C:\ProjectBuild\CruiseControl.NET\server\MHI WorkingDirectory\Source\MyProject.sln" /> </exec> </target> <target name="run" depends="build"></target> <project default="build"></project>

More Stories

Cover Image for Find and FindAll in generic collections

Find and FindAll in generic collections

Weijie Lin
Cover Image for My 2 cents on agile development

My 2 cents on agile development

Weijie Lin