Build文件
Nant的Build文件是用xml写的。每一个文件包含一个工程(project)和几个对象(target),每一个对象包含几个任务(taek)。下面是一个编译HelloWorld(c#)工程的简单build文件。
<?xml version="1.0"?>
<project name="Hello World" default="build" basedir=".">
<description>The Hello World of build files.</description>
<property name="debug" value="true" overwrite="false" />
<target name="clean" description="remove all generated files">
<delete file="HelloWorld.exe" failοnerrοr="false" />
<delete file="HelloWorld.pdb" failοnerrοr="false" />
</target>
<target name="build" description="compiles the source code">
<csc target="exe" output="HelloWorld.exe" debug="${debug}">
<sources>
<includes name="HelloWorld.cs" />
</sources>
</csc>
</target>
</project>
在这个例子里面,有"clean" and "build". 两个对象。缺省时,“build”任务会被调用。
例子
在examples 文件夹内,你能找到运行这些粒子所需的文件。
nant:在debug模式(缺省)下运行nant并构建工程。
nant clean:运行nant并删除已编译好的文件。
nant -D:debug=false:在non-debug 模式下运行nant并生成工程。尽管build文件的debug 属性为真(true),命令行中设置的值不会受影响,就像 <property>
任务中的“overwrite”属性被设置为假(false)。
重要提示:如果产生的文件的日期比源文件的日期早,将仅仅执行像编译器任务这样的任务。如果你在debug模式下编译HelloWorld工程,然后什么东西也不清除,在no-debug模式下重新编译,这种情况就会发生,因为nant工程不需要被重新生成。