Wednesday 8 April 2015

C# - Nant configuration and executing Nant 'echo' message.

Nant is a free build tool for .NET projects(similar to 'Ant' is a build tool for Java), using Nant developer can build(i.e. compile) the project without using visual studio(i.e. code can be compiled outside of Visual Studio).
Nant has support for compiling and executing C#, VB.NET, Nunit and also support for generating NDoc(i.e. creating documentation).

Below are the steps for configuring the Nant:

1. Download Nant latest version from 'http://nant.sourceforge.net/'

Click the "<version>-bin.zip" to download the zip folder.


2. Copy the Nant zip file to some other folder and unzip the Nant binaries.

3. Open the command prompt and type command 'nant
   Note: In command prompt, user should not be in the folder path where the nant zip is extracted.
If the message 'nant' is not recognized...... is displayed, that means Nant is not yet configured in the system.

4. Set the PATH for Nant

Copy the nant bin path in the System Variable
 Ex: 'C:\installs\nant-0.92-bin\nant-0.92\bin'

5. Open the new command prompt again(close the command prompt if already opened) and type 'nant' command.
   Note: In command prompt user should not be in the folder path where the nant zip is extracted.

Nant is configured now.

6. Now lets start by writing Nant script to print echo message.

Sample HelloWorld.build file:
<?xml version="1.0" encoding="utf-8" ?>
<project name="HelloWorld" default="go">

<property name="message" value="Hello World from praveen.!"/>
<target name="go">
<echo message="${message}"/>
</target>

</project>

7. Save the file as 'HelloWorld.build'.

8. open the command prompt and navigate to the path where build script is present.




9. Type command nant in command prompt.
Note: While executing nant command make sure there is only one build file in the folder(i.e there is another approach to execute build file, if there are multiple build files in the folder).

 

No comments:

Post a Comment