Shawn Miller

Automating Your ASP.NET Build and Deploy Process with Hudson

June 23, 20089:12 PM
kick it on DotNetKicks.com

Continuous integration describes a set of software engineering practices that speed up the delivery of software by decreasing integration times.

Hudson is a continuous integration tool written in Java. Our experience has shown that with Hudson's growing list of .NET capable plugins it has become a compeling alternative to CruiseControl.NET, Draco.NET, and other continuous integration servers to come out of the .NET community.

What makes Hudson so great? It's web based GUI not only monitors your build projects, it configures them. No need for hand editing XML files!

Let us walk you through how we build and deploy our ASP.NET web applications using Hudson.  (minor gripe: Hudson's UI is made for a fairly wide web browser)

 

Step 1: Source Code Checkout

We use Hudson's built in SVN source code management feature to grab our latest code.  Alternatively you can use CVS, or install plugins for a variety of systems including Visual Source Safe, Perforce, Mercurial, Git, etc.

 

Step 2: Build

The MSBuild plugin allows Hudson to run MSBuild scripts.  Note that we're asking Hudson to call three targets in our MSBuild file (Build, Clean, Upload). These targets look something like this:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <UsingTask AssemblyFile="$(MSBuildExtensionsPath)\Tasks\FreshLogicStudios.Experiments.FtpTask.dll" TaskName="FtpTask" />
    <PropertyGroup>
        <ProductName>atlas.freshlogicstudios.com</ProductName>
    </PropertyGroup>
  <Target Name="Build">
    <MSBuild Projects="..\..\Framework\Source\Framework.sln" Properties="Configuration=Release" />
    <MSBuild Projects="..\..\Sdk\Source\Sdk.sln" Properties="Configuration=Release" />
    <MSBuild Projects="$(ProductName).sln" Properties="Configuration=Release" />
  </Target>
  <Target Name="Cleanup">
    <FtpTask Action="Cleanup" Address="ftp.freshlogicstudios.com" LocalDir="$(ProductName)" Password="bigboy" RemoteDir="\$(ProductName)" UserName="user" />
  </Target>
    <Target Name="Upload">
    <FtpTask Action="Upload" Address="ftp.freshlogicstudios.com" DirectoryExclusionFilter=".svn|obj|Properties|Web References" FileExclusionFilter="*.cs|*.csproj*|*.pdb" LocalDir="$(ProductName)" Password="bigboy" RemoteDir="\$(ProductName)" UserName="user" />
    </Target>
</Project>

 

Step 3: Deploy

We've setup the last two tasks of the MSBuild file to delete the current contents of our web server then deploy the ASP.NET web application's files using FTP.  MSBuild (nor Hudson for that matter) seem to support FTP out of the box.  We've used a HEAVILY modified version of this FtpTask project.

Our modifications include bug fixes to simply make the FTP transport work, plus the additional directory/file exclusion features you see in the MSBuild XML syntax above.  You'll certainly want to skip those ".svn" folders during deployment, and there's no reason to upload the C# code behind files.

Simply add the directories and files you want to be excluded during the upload process (pipe delimited) to the DirectoryExclusionFilter and FileExclusionFilter attributes of the FtpTask.  Wildcards supported.

You can download the FtpTask binary here.  Copy it to "c:\Program Files\MSBuild\Tasks" and you should be good to go.

 

Thanks to Evan Cowden of NuParadigm for showing me this fantastic tool!