Wednesday, June 2, 2010

Build .NET Project with NAnt

Since NAnt comes with NAnt 0.90 release I was interested to use it with my project IZWebFileManage.

At first look it is powerful tool allows me easy to build project, run tests and package release.

The first task was"build" of course.

For such purpose NAnt offers <csc> task, but using this task I have to declare output type, list of source files, resources etc. It is quite good if you are using Notepad or any other (not Visual Studio) IDE, but I (and I believe most of .NET developers) use Visual Studio and have *.csproj file.

Is there a way to build VS project with NAnt? Yes, you may find it in NAntContrib. It provides <msbuild> task. But problem is that NAntContrib is quite out of date. The last release is on 2006/10/15 and I am not sure it supports NAnt 0.90 and VS 2008

Is there alternative way to build *.csproj? Yes - msbuild command line!
NAnt has <exec> task which run any command line you want.

There is my Default.build file:



<?xml version="1.0" ?>
<project name="IZWebFileManager" default="build"
xmlns
="http://nant.sf.net/schemas/nant.xsd">

<property name="project.config" value="Debug" />

<target name="clean">
<exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
commandline='/t:Clean /p:Configuration=${project.config} /p:Platform="AnyCPU" /v:n'
workingdir="." />
</target>

<target name="version">
</target>

<target name="build" depends="clean, version">
<exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
commandline='/t:Build /p:Configuration=${project.config} /p:Platform="AnyCPU" /v:n'
workingdir="." />
</target>

</project>

I place Default.build file near to *.csproj file and msbuild find it by default, so there is no need to mention name of project file explicitly.

Run build using command line:

>nant build


P.S. After a while I figured out <solution> task. Looks like that is what I need to run msbuild with NAnt. I will discover it...

No comments:

Post a Comment