Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Monday, May 26, 2008

Microsoft .NET Web Application using CruiseControl.NET and NAnt

1 Abstract

The implementation of a reliable build and deployment process is the most important part of the Software Development Life Cycle (SDLC). It is difficult and inconvenient to build and deploy .NET application having multiple projects. Such application complicates the process during manual build and deployment. The CruiseControl.NET and NAnt tools are used to automate the complex build and deployment process.

The CruiseControl.NET is an automated continuous integration server implemented using the Microsoft .NET Framework. It can be used to customize the build process by modifying configuration file (ccnet.config) and also help integration with other external tools like NAnt and Visual Studio. NAnt is an advanced cross-platform XML build system for .NET software. The integration of NAnt script with CruiseControl.NET provides automation to build and deployment process.

This article is about providing ideas, practices, and a platform for standardizing approaches to build and deploy processes. In this article, we’ll review the configuration of CruiseControl.NET with NAnt scripts and executing build and deployment. We’ll see how to create NAnt script and also explore CruiseControl.NET configuration file.

System Architects and .NET developers are the targeted audience for this article who has knowledge of Visual Studio 2005 and XML.

2 and NANT

  2.1 CruiseControl.NET

  2.2 NAnt

  2.3 Why and When to use?

3 build and deployment process

  3.1 Create a sample .NET Web Application

  3.2 Create NAnt scripts for the build and deployment

  3.3 Configure NAnt scripts with CruiseControl.Net

  3.4 Execute build and deploy

4 Best Practices

5 Conclusion

6 abbrEvations, Acronyms and Nomenclature

7 Disclaimer

2 and NANT

This section describes the significance of CruiseControl.NET and NAnt tools.

2.1 CruiseControl.NET

CruiseControl.NET is an Automated Continuous Integration [ACI] server implemented using the Microsoft .NET Framework. ACI is a process which monitors the version control system for changes/modifications and automatically runs the build process. CruiseControl.NET can be configured to run build and deployment automatically by setting its config file to run at particular time.

The CruiseControl.NET has a user interface called “Web Dashboard” using which one can execute and schedual build projects. It also provides consolidated log report for each execution and maintains the history.

Advantages of CruiseControl.NET

  • Integration with Visual Source Safe control (VSS)
  • Integration with other external tools, such as NAnt and Visual Studio
  • Can build multiple projects on one server
  • Can execute the build manually or schedule it at a suitable daytime
  • The scheduling of the build is as easy as modifying a XML based configuration file
  • The build report and logs are available at one place which makes it easy to track the history of all the builds.

2.2 NAnt

NAnt is an advanced cross-platform XML build system for .NET software available free as an open source. NAnt parses XML build files and executes the instructions gained from the file. The XML build file consists of a set of instructions for the build of a .NET solution. The build process includes tasks like compiling source code, running unit tests, configuring build-specific settings, etc. NAnt, as a tool, helps automate the build process by providing necessary power and flexibility to highly customized build actions of specific applications.

A normal build process mentioned below can be automated using NAnt.

  • Extract the latest source from Visual Source Safe (VSS)
  • Configure the build (Output of the build into a directory, the build number, scheduling, log, etc)
  • Compile the code
  • In order to deploy, package the output

NAnt enables one to automate the aforementioned steps instead of manual process of running commands and copying files. The NAnt script doesn’t require any special editor, can be created using Notepad (or XML editor) and saved as “.build” extension.

Advantages of NAnt:

  • Used to build, compile and run the .NET projects
  • It can easily handle the build although different modules of the project written in different languages like C#, VB, etc.
  • NAnt can easily integrate with NUnit testing tool - NUnit 2.0
  • NAnt can also perform other tasks like creating, deleting, copying files or directories, sending emails, zipping files, etc.
  • It allows to integrate .NET assemblies in the script which makes it easy to call any customized Method or Function.

2.3 Why and When to use?

The CruiseControl.NET and NAnt have some advantages over the new build and deployment tools like Visual Studio Team System (VSTS) and Team Foundation Server (TFS). Due to cost effective, reusability, open source and minimum infrastructure requirements makes CruiseControl.NET and NAnt more effective for the low budget and less resources project.

The comparison between tools, CruiseControl.NET/NAnt and VSTS/TFS used for build and deployment process is mentioned below:


CruiseControl.NET, NAnt (using VSS)



Free and Open Source

Requires License

Operation System

Windows 2000, XP or higher

Windows 2003

Installation & Configuration


Time consuming and complex

Source Control

Visual Source Safe (VSS)

Inbuilt, Team Foundation Version Source Control (TFVC)


VSS based security on Source files

Windows/ Active Directory based security


File System ( VSS)

SQL Server 2005 (TFVC)

Features :


Multiple Check Out

Not Supported by VSS


File Merge

Not Supported by VSS


Manual and Automated Merge

File Lock

Exclusive Lock.

Once file check-out, no one can check out or in

Lock Types:

None: shared check-out

Check-in: Others can check-out, but not check-in

Check-out: exclusive lock, no one can check out or in


(Process of saving partial\ incomplete code in source control without Check-In)

Not Supported by VSS

Supported by Team Foundation Version Control

NAnt script knowledge


Not required

Table 2.3.1: Comparison between the tools CruiseControl.NET/NAnt and VSTS/TFS.

If you have small team size and require cost effective build and deployment option, then CruiseControl.NET and NAnt can be effective. The correct methodology of implementation of build and deployment process using NAnt scripts makes it reusable for the other projects with less effort.

The next section will guide you to create build and deployment process for the sample Web Application.

3 build and deployment process

This section provides information on the steps to be followed in order to create build and deployment process for a sample Web Application using CruiseControl.NET and NAnt.


3.1 Create a sample .NET Web Application

  1. In Visual Studio 2005, create a new web application “DemoBuildandDeployment” and provide the path c:\demo\demoBuildandDeployment
  2. Add the “DemoBuildDeployment” project to Visual Source Safe (VSS)

3.2 Create NAnt scripts for the build and deployment

NAnt script file has the XML command tags, which make it very easy and convenient to write. NAnt script file starts with the <project> tag where the project name can be defined as an attribute. This is a root node of a build script and each script has one <project> tag.

<project name="AutoBuild">


<project> can have multiple <target> tags. A target is a discrete piece of work that can consist of zero or more tasks to be executed. Targets can be dependent on each other. Targets behave like a “Method” in .NET code which means they can be called within the build file or from another build file.

<project name="AutoBuild">
<target name="NewBuild">
<nant> tag is used to call particular task of build file whereas <property> tag is used to provide an input parameter to the build file. As shown below example, target <NewBuild> of file is called using <nant> tag and the “branch” and “source.path” are passed as input parameter to file using <property> tag.
<project name="AutoBuild">
<target name="NewBuild">
<echo>Create New Build and Deployment</echo>
<nant buildfile="" target="NewBuild">
<property name="branch" value="$/demo/"/>
<property name="source.path" value="C:\demo\"/>

As mentioned below, <vssget> tag is used to get the latest source code from Visual Source Safe (VSS).

username=”<User ID of VSS>”
password="<Password of VSS>"
localpath="<Working root directory on local system>"
dbpath="<Full srcsafe.ini path>"
path="<VSS path>"/>

The Visual Studio 2005 has an executable ‘MSBuild.exe’ used to compile and build application. The <msbuild> tag is used to build the project.

<msbuild project = "<Project Path\solution name.sln">
<arg value="/property: Configuration=debug; outdir=bin\Debug\" />
<arg value="/t: Rebuild" />

In order to simplify the build and deployment process of the sample Web Application, create four build scripts as mentioned below.


This script would contain all the information of input parameters such as source code path, Visual Source Safe path, and deployment folder.


This file would contain the commands to build the web application project in debug and release mode.


This file would contain information to deploy the Web Application to virtual directory path of Web Application. (c:\Apps\Demo\DemoBuildandDeployment)


This file would be used to get the latest version of source code from VSS. It would call to build the latest source code and to deploy the project.

The logical flow of script execution is shown below.


Figure 3.2.1: Logical flow of build scripts

Detail implementation of each script is explained as below:

1. script is responsible for initiating the build by setting the input parameters.

Input parameters:

branch: VSS root branch path

source.path: Working directory path for Web Application where source code is located.

destination.path: Path of folder where virtual directory is mapped for website.


Figure 3.2.2: file

Execution of file will call “NewBuild” target of file and

provides the input parameters.


<echo> tag is used to provide comments in log file or on command prompt

2. script is responsible to call another script step by step. This script calls to build the web application then call to deploy web application at destination location.


Figure 3.2.3: file


The property {db} is set to the VSS path where the srcsafe.ini file is located.

3. script is responsible for building the Web Application, in the real sense, using <msbuild> command in debug and release mode.


Figure 3.2.4: file

<delete> tag is used to delete all the existing DLLs and other files residing in Debug and Release folder. In <msbuid> tag, argument “/property: Configuration” is used to define the mode of build. It can be set as either debug or release.

4. script is responsible for deploying the DLLs and configuration files to destination folder.


Figure 3.2.5: file

Once all scripts are ready, they would require configuring with CruiseControl.NET to execute. The next section 3.3 describes the configuration of scripts.

3.3 Configure NAnt scripts with CruiseControl.Net

CruiseControl.NET tool has a configuration file (ccnet.config) which can be configured to run the NAnt scripts. Multiple projects can be configured to execute using this file.

The ccnet.config file is located at C:\Program Files\CruiseControl.NET\server\ccnet.config.

Some of the important XML tages used in ccnet.config file are as mentioned below:

XML Tags



Define the project. ccnet.config file can be configured for multiple project execution using this tag


Web URL of CruiseControl.NET


NAnt script files which require to call


Target to call from NAnt script


Location of build scripts


Logging the executable error


Call the Nant script at defined schedule

Table 3.3.1: XML tages used in ccnet.config file

Below is the config file configured to run our build and deployment process.

<project name="Demo Build and Deployment project">
<executable>C:\Program Files\nant\bin\nant.exe</executable>
<xmllogger logDir="C:\Demo\Log\" />
<scheduleTrigger time="15:00" buildCondition="ForceBuild">
<scheduleTrigger time="20:00" buildCondition="ForceBuild">

3.4 Execute build and deploy

To execute the Build and Deployment project access, the CruiseControl.NET Web Dashboard through the web address http://localhost/ccnet/ViewFarmReport.aspx.


Figure 4.4.1: Snapshot of CruiseControl.NET Web Dashboard before execution of the project

Click the “Force” button to start the build and deployment process and the “Activity” column status will change from “Sleeping” to “Building” which will revert back to “Sleeping” once the job is finished.

As shown in Figure 4.4.2 below, the status for “Last Build Status” column will change to “Success” once build is complete without any error. In order to view the log file of specific project, click on Project Name link which would provide the details of execution logs and in case of errors helps debugging.


Figure 4.4.2: CruiseControl.NET Web Dashboard after executing the project


The automated build and deployment can also be executed using manual command prompt as below:

"C:\Program Files\NAnt\bin\NAnt.exe" -v NewBuild

4 Best Practices

This section provides the details of some of the best practices that should be followed for automated build and deployment using CruiseControl.NET and NAnt.

· Based on the deployment environment, the configurable file like “Web.config” should be created at run time. In order to achieve this, a console .NET application can be created to generate the Web.config file which can be called from NAnt script. This will avoid manual modification of Web.config file for the different environments (Like development, Integration, System Acceptance Test, Test for Production, Production, etc.).

· Create separate NAnt script for each build and deployment process so that Build folder (Containing DLLs, aspx, etc.) is created only once and that can be used for deployment of different environments using deployment scripts. This will avoid building project multiple times for the different environments.

· VSS files can be marked with a Label to mention the build version which will help track the file used in a particular version of build.

• In order to receive a notification for the successful completion of the build and

deployment process, one can add <email> section in ccnet.config for the project.

5 Conclusion

In this article we learned to create NAnt script, configure NAnt scripts to CruiseControl.NET and explore ccnet.config file. The automated build and deployment process of .NET application using a CruiseControl.NET and NAnt tools is cost effective, reusable, easily configurable and requires minimal or no additional infrastructure setup. To make the build and deployment reusable for different projects, NAnt scripts should be divided based on logical task.

The next step would be to advance the build and deployment implementation based on your project requirements and using suggested best practices in this article.

6 abbrEvations, Acronyms and Nomenclature

Terminology  and Description

ACI Automated Continuous Integration
IIS Internet Information Services
TFS Team Foundation Server
TFVC Team Foundation Version Control
VSS Visual Source Safe
VSTS Visual Studio Team System
XML Extensible Markup Language

NAnt script/ build script/ build file
An XML file consist of a set of instructions for the build of a .NET solution

7 Disclaimer

This paper should not be interpreted as an endorsement of any software products.

Post a Comment

Anonymous said...

Thank you so much for this very informative article. It really gave me a headstart on using NAnt scripts! :D

Anonymous said...

Thanks for the great artilce. really useful to me.

Anonymous said...

Thanks for the sharing this website. it is very useful professional knowledge. Great idea you know about company background.
web application development