NAnt


NAnt is an XML-based free build tool for .NET applications. If you are a Java developer, you are probably familiar with Ant (http://ant.apache.org/). Ant has become an essential tool for almost any Java-based development. Developers have come to like Ant in favor of the build capabilities available in Java development tools. Based on the success of Ant, NAnt is an open source project that provides the capabilities of Ant to the world of .NET. Similar to Ant, to use NAnt, developers are expected to write a build file for their applications that contains a set of tasks (which can have dependencies on each other). When the NAnt build system is invoked, very similar to the "make," the tool compiles and/or executes the application. A key benefit of using a tool like NAnt is to establish automated build processes and times. For developers who prefer using the .NET Framework command-line tools, NAnt is an indispensable tool.

To understand NAnt, take a simple scenario of how NAnt can be used to build and execute an application. As mentioned earlier, a NAnt build file is made up of a series of related tasks (called targets) identified by their names . Listing 6.1, for instance, has two targets: build and run. The run target is dependent on the build target. The build target, in turn , uses the command-line C# compiler to compile the source files into the executable using the <csc> task. The run target uses the < exec > task to run the executable.

Listing 6.1 Simple NAnt Build File (default.build)
 <?xml version="1.0"?> <project name="Hello World" default="run">    <property name="debug" value="true"/>    <target name="clean">       <delete>          <fileset>             <includes name="HelloWorld.exe "/>          </fileset>       </delete>    </target>    <target name="build">       <csc target="exe " output="HelloWorld.exe " debug="${debug}">          <sources>             <includes name="HelloWorld.cs"/>          </sources>       </csc>    </target>    <target name="run" depends="build">       <exec program="HelloWorld.exe "/>    </target> </project> 

After you have developed the build file (and the associated source code for your application), run NAnt. Make sure that you have NAnt's bin directory in your PATH variable.

 
 E:\hks\DotNet\Chapter 6>nant NAnt version 0.8.3 Copyright (C) 2001-2003 Gerry Shaw http://nant.sourceforge.net Buildfile: file:///E:/hks/DotNet/Chapter 6/default.build build:       [csc] Compiling 1 files to E:\hks\DotNet\Chapter 6\HelloWorld.exe. run:      [exec] HelloWorld.exe             Hello Again Total time: 3 seconds. BUILD SUCCEEDED 

SHOP TALK : ANT AND NANT

Ant has become the de-facto standard for build tools for Java and J2EE (Java 2 Enterprise Edition) applications. On the other hand, Visual Studio has always been a popular tool for Microsoft-centric development. With the release of Visual Studio .NET, this trend is likely to go and Visual Studio .NET will likely emerge as the standard development (including build) tool. It will be interesting to watch the popularity of a build tool such as NAnt, which I believe can be very useful in automated builds for distributed projects. Also, with .NET Framework, Microsoft has introduced free command-line compilers for the various programming languages, and this could itself give rise to the development of command-line builds as well. Another unique advantage that is available with NAnt is NUnit, which provides a framework for creating and running test cases. NUnit, like NAnt, also builds on the popularity of the de-facto test case framework for Java applications ”JUnit.


The heart of the NAnt build engine is the series of tasks. Currently, a set of predefined tasks is available to automate most of the build process. Frequently used tasks and their brief functions are shown in Table 6.1. In addition, you can also develop your own tasks.

Table 6.1. NAnt Predefined Tasks

TASK(S)

DESCRIPTION

<al>

Invoke the assembly linker

<cl>

Invoke C++ compiler

<copy>

Copy files

<csc>

Invoke C# compiler

<cvs-*>

Checking-in/checking-out files from CVS-based Source Code Control system

<delete>

Delete a set of files

<exec>

Execute programs

<foreach>, <if>, <ifnot>

Basic looping or conditional constructs

<jsc>

Invoke Jscript.NET compiler

<link>

Invoke the linker

<mail>

Send an email using SMTP, for instance, to notify any build errors

<nant>

Build a subproject

<ndoc>

Create documentation using NDoc

<nunit>

Run unit tests based on NUnit Framework

<readregistry>

Read Windows Registry information

<vbc>

Invoke Visual Basic .NET compiler

<vjc>

Invoke Visual J# compiler

For more information and/or to download NAnt, visit http://nant.sourceforge.net.



Microsoft.Net Kick Start
Microsoft .NET Kick Start
ISBN: 0672325748
EAN: 2147483647
Year: 2003
Pages: 195
Authors: Hitesh Seth

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net