Click here to Skip to main content
15,745,306 members
Articles / Web Development / ASP.NET
Posted 10 Dec 2007

Tagged as


37 bookmarked

Automating ASP.NET Web Application Project Build Using CruiseControl.Net and MSBuild

Rate me:
Please Sign up or sign in to vote.
2.92/5 (6 votes)
20 Jul 2008CPOL2 min read
This article describes how to automate an ASP.NET Web Application project build using CruiseControl.Net and MSBuild


I was recently introduced to CruiseControl.Net and have been using it for my team's build automation. Let me explain my development environment before proceeding into the details of configuration. Ours is a Visual Studio 2005 Web Application project. It follows a three tiered (Presentation Layer, Business Layer, Data Access Layer) architecture. I usually follow the Build-> Publish <Web Site> option of Visual Studio IDE to build the project and pass the build to the testing department. This option allows to publish the application to a specific disk path, set through the Publish Web dialog box.


With CruiseControl.Net, I needed a way to automate this process. In this article, I explain how I managed to do it using MSBuild, Microsoft's build engine. Here, I would like to add a disclaimer that this may not be the best way of automating a build. I am just describing my way of doing it and it works for me. Hope it sounds meaningful and will be of help to someone.


The following are the contents of my MSBuild script:

<Project DefaultTargets="DoPublish" 
  <PropertyGroup Condition ="$(CCNetWorkingDirectory) == ''">
    <DefaultBinFiles Include="$(SourceFileRootFolder)\DefaultBinFiles\*.*"/>
    <ProjectBinFiles Include="$(SourceFileRootFolder)\$(WebFolder)\bin\*.*"/> 
  <Target Name="CleanSource">
    <Message Text="Removing all source files from $(ReleaseFolder)" />
    <RemoveDir Directories="$(ReleaseFolder)" />
  <Target Name="DoPublish">
    <MSBuild Projects="$(SourceFileRootFolder)\MyProject.sln" Targets="Clean;Build" />
    <CallTarget Targets="CleanSource"/>
    <MSBuild Projects="$(SourceFileRootFolder)\$(WebFolder)\MyProject.Web.csproj" 
	Properties="OutDir=$(ReleaseFolder)\" ></MSBuild>
    <Copy SourceFiles="@(DefaultBinFiles)" 
    <Copy SourceFiles="@(ProjectBinFiles)" 

I keep a separate folder "DefaultBinFiles" whose contents I want to be placed in the bin files of the build. This may have a copy of any third party assemblies registered in the cache or other com references being used in the project. The ProjectBinFiles have the assemblies created in the project's bin folder. 

The MSBuild element performs a clean build of the solution. CleanSource deletes the release folder. The next MSBuild command instructs to execute _CopyWebApplication and _BuildWebOutputGroupOutput targets. These targets can be found in Program Files\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets. This also requires a tweak in the web csproj file. Add the following section to the csproj file anywhere between the Project tags. Note that csproj file is actually an MSBuild script.


By default, the build outputs are placed under _PublishedWebsites subfolder. The above section eliminates this and places the build right under the custom folder set in the ReleaseFolder tag. The next two copy elements in the script recursively copy the contents of the DefaultBinFiles and ProjectBinFiles folders to the bin folder of the ReleaseFolder.

Add the following XML to the ccnet.config file:


As can be seen, CruiseControl.Net is instructed to use msbuild to carry out the build task provided in c:\TestCC\MSBuild.xml. DoPublish is the target to execute.


Following the above MSBuild configuration would place the build output of an ASP.NET Web application project to a specific folder on disk and linking it to CruiseControl automates the whole build process. Information for setting up CruiseControl.Net can be found at How to Setup CruiseControl.NET for Starters


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Team Leader
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionPowershell Pin
kiquenet.com20-Feb-13 23:55
professionalkiquenet.com20-Feb-13 23:55 
GeneralCCNet XmlConfig Plugin Pin
void leenux();16-Apr-11 7:38
void leenux();16-Apr-11 7:38 
GeneralMy vote of 2 Pin
GilesHinton30-Nov-09 2:11
GilesHinton30-Nov-09 2:11 
GeneralRe: My vote of 2 Pin
Michael Collns26-Dec-09 9:20
professionalMichael Collns26-Dec-09 9:20 
AnswerStatement about tweaking web project is unnecessary Pin
GilesHinton30-Nov-09 2:10
GilesHinton30-Nov-09 2:10 
GeneralResolve project dependencies Pin
ByteGuru4-Mar-09 1:52
ByteGuru4-Mar-09 1:52 
Generalbuild project Visual Studio IDE vs msbuild.exe Pin
pghn6-Nov-08 7:31
pghn6-Nov-08 7:31 
QuestionAutomatically creates a _PublishedWebsites folder. Pin
VS2008Developer12-Jul-08 4:18
VS2008Developer12-Jul-08 4:18 
AnswerRe: Automatically creates a _PublishedWebsites folder. Pin
Judy Joy16-Jul-08 19:57
Judy Joy16-Jul-08 19:57 
AnswerRe: Automatically creates a _PublishedWebsites folder. [modified] Pin
naalexander13-Nov-10 10:58
naalexander13-Nov-10 10:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.