5,550,131 members and growing! (19,854 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate License: The Code Project Open License (CPOL)

Automating ASP.NET Web Application project build using CruiseControl.Net and MSBuild

By Judy Vinu

This article describes how to automate an ASP.NET Web Application project build using CruiseControl.Net and MSBuild
.NET (.NET 2.0, .NET), ASP.NET, Architect, Dev, QA, Design

Posted: 10 Dec 2007
Updated: 20 Jul 2008
Views: 15,249
Bookmarked: 16 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
5 votes for this Article.
Popularity: 2.17 Rating: 3.10 out of 5
1 vote, 20.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
2 votes, 40.0%
4
2 votes, 40.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

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 tired (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 testing department. This option allows to publish the application to a specific disk path, set through the Publish Web dialog box.

Background

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.

Description

The following are the contents of my MSBuild script:

<Project DefaultTargets="DoPublish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <SourceFileRootFolder>$(CCNetWorkingDirectory)</SourceFileRootFolder>
    <WebFolder>MyProject.Web</WebFolder>
    <ReleaseFolder>c:\TestDeploy\v$(CCNetLabel)</ReleaseFolder>
  </PropertyGroup>
  <PropertyGroup Condition ="$(CCNetWorkingDirectory) == ''">
    <SourceFileRootFolder>c:\testcc</SourceFileRootFolder>
    <ReleaseFolder>c:\TestDeploy\v</ReleaseFolder>
  </PropertyGroup>
  <ItemGroup>
    <DefaultBinFiles Include="$(SourceFileRootFolder)\DefaultBinFiles\*.*"/>
    <ProjectBinFiles Include="$(SourceFileRootFolder)\$(WebFolder)\bin\*.*"/> 
  </ItemGroup>
  <Target Name="CleanSource">
    <Message Text="Removing all source files from $(ReleaseFolder)" />
    <RemoveDir Directories="$(ReleaseFolder)" />
  </Target> 
  <Target Name="DoPublish">
    <MSBuild Projects="$(SourceFileRootFolder)\MyProject.sln" Targets="Clean;Build" />
    <CallTarget Targets="CleanSource"/>
    <MSBuild Projects="$(SourceFileRootFolder)\$(WebFolder)\MyProject.Web.csproj" 
Targets="_CopyWebApplication;_BuiltWebOutputGroupOutput" Properties="OutDir=$(ReleaseFolder)\" ></MSBuild>
    <Copy SourceFiles="@(DefaultBinFiles)" DestinationFolder="$(ReleaseFolder)\$(WebFolder)\bin\"></Copy>
    <Copy SourceFiles="@(ProjectBinFiles)" DestinationFolder="$(ReleaseFolder)\$(WebFolder)\bin\"></Copy>
  </Target>
</Project>

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.

<PropertyGroup>
    <WebProjectOutputDir>$(OutDir)\$(MSBuildProjectName)</WebProjectOutputDir>
  </PropertyGroup>

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 copies the contents of the DefaultBinFiles and ProjectBinFiles folders to the bin folder of the ReleaseFolder.

Add the following xml to the ccnet.config file:

<msbuild>
  <executable>C:\WinNT\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
  <workingDirectory>c:\TestCC\</workingDirectory>
  <projectFile>MSBuild.xml</projectFile>
  <targets>DoPublish</targets>
  <timeout>300</timeout>
  <logger>ThoughtWorks.CruiseControl.MsBuild.XmlLogger,ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>

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.

Conclusion

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.

 

License

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

About the Author

Judy Vinu



Occupation: Team Leader
Location: India India

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Search Search Messages 
 Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
Subject  Author Date 
QuestionAutomatically creates a _PublishedWebsites folder.memberVS2008Developer5:18 12 Jul '08  
AnswerRe: Automatically creates a _PublishedWebsites folder.memberJudy Vinu20:57 16 Jul '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 Jul 2008
Editor:
Copyright 2007 by Judy Vinu
Everything else Copyright © CodeProject, 1999-2008
Web09 | Advertise on the Code Project