Off on my way to CI

I am sure there are a lot of developers out there who already use Continuous Integration (CI). personally I plan on moving over to a CI environment but I want to dip my toes in the water first to see how the various aspects of CI can work for me. Readers of my previous blog will know that I have already set up Subversion. More recently I have started to use NAnt and in this post I will quickly cover how I set it up to be run from VS 2005.

For those of you who don't know what NAnt is, basically it is an automated build tool. It is run from the command line and reads configuration data from a .build file.

Why use NAnt over Visual Studio?

NAnt doesn't need VS to be running to run a build job, so it can be scheduled to run at any time.
It can automatically check out code from your source control.
It can run any unit tests.
If you have any other files which you want copied over to the build directory, you simply specify them.

Firstly you can get NAnt from here.

Once downloaded, extract it to somewhere on you drive.
I use C:\Program Files\NAnt

In Visual Studio go to Tools >> External Tools then click on Add.

External_tools_nant

You need to specify the buildfile for NAnt. I keep my build configuration for all projects in a file called nant.build in the root of my project. This way going to Tools >> NAnt will build the project I am currently in without having to pass any other parameter. For arguments, use this.

-buildfile:$(ProjectDir)\nant.build

The build file is actually an XML document where you specify tasks for NAnt. Within this XML are <project> and <target> tags where you specify the tasks.

<?xml version="1.0"?>
  <project name="myApp" default="build" basedir=".">
    <target name="build">
     <delete dir="nant_build" />
     <mkdir dir="nant_build" />
     <mkdir dir="nant_build\Docs" />
     <mkdir dir="nant_build\Images" />

Add <sources> and <references> for your project like this.

<csc target="exe" output="nant_build\myApp.exe">
        <sources>
          <includes name="myClasses.cs"/>
          <includes name="stuff.cs"/>
          <includes name="Web References\webbyservice\Reference.cs"/>
        </sources>
      <references>
        <includes name="myDLL.dll" />
      </references>
</csc>

If there are any files you want to copy over to the build directory use the <copy> tag with the todir attribute like this.

<copy todir="nant_build">
    <fileset basedir=".">
        <include name="ReadMe.txt" />
    </fileset>
</copy>

Now running Tools >> NAnt will compile your app and copy any additional files to a nant_build directory.

There is so much more to NAnt which I haven't even touched on here. As I explore it more I will blog my findings.

p.s. No I don't actually call my files myClasses,cs or stuff.cs, that is just for an example. Although I did know a developer who had methods called DoStuff().

3 Comments

  • Excellent blog post, thanks! The company I work for uses NAnt to publish our web apps, and we've been going through the command line interface. This could allow us to release our apps right from Visual Studio, which I think would be a good thing. Thanks!

    James

  • Agh nice post - something I am getting more and more interested in and will keep an eye on your posts.

    Very helpful thanks.

    G

  • If I recall correctly, there is a solution task for nant which will save you from redefining what to include in the compilation.

    I haven't used nAnt since MsBuild came out, but I still use CCNet as the integration server.

    With my CI builds, I prefer to build exactly what the developers will build on their dev machines. We use VMs for dev and the CI build server is setup the same as a developers station. Procution/release builds are a separate step.




Comments have been disabled for this content.