Wednesday, March 26, 2008

NAnt how to...(for beginners)

Installation
NAnt is available in either a source or binary distribution. The binary distribution is all you need to use NAnt to build your projects, including creating your own custom tasks, types and functions.
If you are upgrading NAnt from a previous version, you must never install over the top of your previous installation. Delete or rename the existing installation directory before installing the new version of NAnt.

Installing from binaries
1. Download the binary distribution archive. Either nant-bin.zip or nant-bin.tar.gz, the contents of each archive are the same. http://nant.sourceforge.net/
2. Remove any previous versions of NAnt you may have installed.
3. Extract the contents of the archive to the location you wish to install NAnt (eg: C:\Program Files\NAnt in windows, or /usr/local/nant in Linux)
4. Depending on your environment, create a wrapper script to run NAnt

SET Environment Variables
To set environment variables follow the below steps:
1. Goto System Properties->Advanced. Click the tab named “Environment Variables”.

2. Add new entry for NAnt as below


Variable value is the path where NAnt.exe is installed.
Creating Default.Build File
1. Create NAnt Build file something similar to the below screen shot.
2. Build File is a XML with a file extension “BUILD”. This file contains the build information that needs to be processed by NAnt.
A Sample Build file is as below

Note: The build file has to have the tag. Else NAnt will throw out error stating “Build Failed – Root Element missing”
Verifying the Installation
1. Once the build file is created.
2. Using the command window, Open the directory where the NAnt.exe resides, in this case it is “C:\nant-0.86-beta1\bin”.
3. Run Nant (see below)
4. You should get see the output “Build Succeeded” message.

Adding contents to the Build File
1. Once the build file is successful. We could start adding the adding the build script.
2. Example: Lets add a script to open a Notepad window from NAnt. Add the following code in the build file as “



Your final file would looks something like below

Executing the Build
1. Open the command window go to the NAnt.exe folder and execute the following
NAnt run2
Where run2 happens to be the “Target” name in the Temp.Build file.

2. Immediately you should be able to see a new notepad window open up.

No comments: