You may have heard of Continuous Integration (CI) for .NET, but perhaps thought it would take too long to install and configure the tools. By integrating the CC.NET, NAnt, and Subversion tools, you can quickly create a robust CI solution. In this entry, I walk you through the setup and configuration of these tools, step by step.
There are many ways to define CI, but just think of it as a process of integrating your software when a change is applied to your SCM repository. This may include compiling, inspecting, testing, deploying, and generating feedback.
Prerequisites
You need to install and configure IIS and have access to a Subversion repository. If you’d like a Subversion project to use for this example, use http://www.qualitylabs.org/svn/ndbunit/. Note: You will need an account established at qualitylabs.org.
Step 1 - Download and install tools
Subversion is the SCM tool used to manage your source code. Extract the Win32 version of the Subversion zip (svn-win32…) file to a designated directory
NAnt is the build scripting tool to build your software. Extract the NAnt zip file to a designated directory
CC.NET is the CI tool to run your build script whenever a change occurs in your SCM. Save and run the installation .exe file. CC.NET should be installed on a separate machine than the developer machines. However, for the purposes of this example, you will be installing CC.NET on the same machine.
Step 2 - Configure Subversion
Create a Windows environment variable called SVN_HOME. The value should equal the location of the Subversion installation directory from step 1. Add %SVN_HOME%\bin; to the System PATH environment variable.
svn. You should receive a message like: Type ’svn help’ for usage.
Step 3 - Configure NAnt
nant. You should receive a message like: BUILD FAILED. Could not find a ‘*.build’ file…
Step 4 - Create NAnt build file
Create the following and save as default.build.
<?xml version="1.0"?>
<project name="HelloWorld" default="build">
<target name="init" depends="clean" />
<target name="clean" />
<target name="checkout"/>
<target name="compile"/>
<target name="deploy"/>
<target name="test"/>
<target name="inspect"/>
<target name="build" depends="init, checkout">
<call target="compile" />
<call target="inspect" />
<call target="test" />
<call target="deploy" />
</target>
</project>
nant in the same directory where you placed the default.build file. After a short time, BUILD SUCCEEDED should be displayed.
Step 5 - Configure CC.NET
Go to the directory where you installed CC.NET in Step 1. From here, go to the server subdirectory. In this directory there is a file called ccnet.config. Open this file and add the following:
<cruisecontrol>
<project name="HelloWorld">
<schedule type="schedule" timeout="60000"/>
<modificationDelay>10000</modificationDelay>
<sourcecontrol type="svn">
<trunkUrl>http://www.qualitylabs.org/svn/ndbunit/</trunkUrl>
<executable>C:/dev/testearly/svn-win32-1.3.1/bin/svn.exe</executable>
<username>george.washington</username>
<password>M@rtha</password>
<workingDirectory></workingDirectory>
<artifactDirectory></artifactDirectory>
<autoGetSource>true</autoGetSource>
</sourcecontrol>
<build type="nant">
<executable>C:/dev/testearly/nant-0.85-rc3/bin/nant.exe</executable>
<baseDirectory>C:/dev/testearly/</baseDirectory>
<buildFile>default.build</buildFile>
<targetList>
<target>build</target>
</targetList>
<buildTimeout>300000</buildTimeout>
</build>
<publishers>
<xmllogger>
<logDir>.websitelog</logDir>
</xmllogger>
</publishers>
</project>
</cruisecontrol>
Update the trunkUrl attribute to the location of your Subversion server and project. Open a web browser and type:
http://localhost/ccnet/
The following should be displayed:
Troubleshooting
You may get tripped up with a few problems along the way. Here’s a list of some of some of the issues along with some troubleshooting techniques:
Conclusion
Of course, this is a very basic solution of integrating these tools. You’ll want to expand the NAnt build script to provide meaningful activities such as running automated tests and inspections and deploying the software. If you need to use a different SCM, you can simply change the source control configuration block in ccnet.config. By integrating your software upon any material source code change, you can better ensure that you will have working software by running through consistent, repeatable steps that compile, test, inspect, and deploy your software (into a development/testing environment). Integrate early. Integrate often.