Ramping up with NAnt for automated builds – level 300

At first glance, the NAnt .build files may seem daunting, especially the really long ones, but the documentation for NAnt is superb!

I wanted to start with a real VS solution instead of the trivial HelloWorld .cs file, so I used my Model-View-Presenter demo solution.  Since this was a Visual Studio solution, all I had to do was add a Solution task in the build file.

Here is my build file.  Now if that doesn’t convince you that automated builds aren’t that hard, I don’t know what will!

<project name=”Model View Presenter with Repository” default=”rebuild”>
    <property name=”configuration” value=”release”/>
   
    <target name=”clean” description=”Delete all previously compiled binaries.”>
        <delete>
            <fileset>
                <include name=”**/bin/**” />
                <include name=”**/obj/**” />
                <include name=”**/*.suo” />
                <include name=”**/*.user” />
            </fileset>
        </delete>
    </target>
   
    <target name=”build” description=”Build all targets.”>
        <call target=”build.solution”/>
    </target>
   
    <target name=”rebuild” depends=”clean, build” />

    <target name=”build.solution”>
        <solution configuration=”${configuration}” solutionfile=”MVPWithRepository.sln” />
        <property name=”expected.output” value=”View/bin/${configuration}/View.exe”/>
        <fail unless=”${file::exists(expected.output)}”>Output file doesn’t exist in ${expected.output}</fail>
    </target>
   
</project>

4 comments

  1. Joshua Flanagan

    Thanks for the great example. This is exactly how I planned on easing into the NANT world (using the solution task instead of completely abandoning VS.NET), but still wasn’t sure how painful it would be. This makes it clear that it should be a simple and straightforward.

  2. Richard Slade

    Trying to set up nant for the first time as a noob to it all.. this is the first decent full example that has got a build working. thank you!

  3. Steve Hebert

    I blogged about my build automation adventures last year. I started with NAnt and still use it for one portion of the build but switched to Visual Build Pro for the overall process. For <$200 I was able to implement my full build process including source code checkout/mod/checkin, project building and moving to a staging area in one day.

    I did some bits for assembling a Sql Upgrade Script using NAnt and blogged the associated code….
    http://codebetter.com/blogs/steve.hebert/archive/category/1057.aspx

  4. Jason Meridth

    Thank you. Thank you. Thank you.

    I’ve been looking everywhere for a global delete to allow for rebuilds.

    Very cool.

Comments are closed.