星期四, 4月 20, 2006

NAnt (1)

Before .Net 2.0, if you don't use IDE to build project, and you want to use a simple command to build project, you have 3 options:
  1. write your own batch file
  2. Makefile
  3. NAnt

After .Net 2.0, you have another option: msbuild.

NAnt series articles are focused on NAnt, but why NAnt ? Why use NAnt??
Because I want.

Cross platform? Makefile, msbuild (mono had ported and named xbuild) can do this too.
Simple? I think Makefile is simpler than NAnt.
Functionality? msbuild is powerful too.
So I say, "Because I want.".

Ant is a very important tool on java platform, so NAnt team port Ant to .Net and name "NAnt", it means .Net Ant.
The official site is at http://nant.sourceforge.net
After you download and unzip the zip file, you can use it, no more special installation steps, even Linux.
I suppose you put the unziped files in c:\tools, and named "nant".

No more nonsense words. Let's start the first sample.
I think that lots of people are used to develop with Visual Studio.Net.

So, create a windows form project and make sure it can be built. (Or you can try your project.)
Then create a text file in project directory, and named "your_project.build" (yes, "your_project.build" can be replaced.)
Put the following text:
<?xml version="1.0"?>
<project name="your_project" default="build">
<property name="nant.settings.currentframework" value="net-1.1"/>
<target name="build">
<solution configuration="release" solutionfile="your_project.sln" />
</target>
</project>


Save the file, then enter command prompt, type
c:\tools\nant\bin\nant


That's all.
Why is this sample so simple? Because NAnt can parse Visual Studio solution file after 0.85.2296.
Just use the task: solution, and NAnt will parse the solution file and build.
But unfortunately, NAnt don't support Visual Studio .Net 2005 yet, even the latest version.

沒有留言: