<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Language" content="en-ca" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="Build Files" /> <link rel="stylesheet" type="text/css" href="../style.css" /> <title>NAnt - Build Files</title> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="2" class="NavBar"> <tr> <td class="NavBar-Cell"> <a title="NAnt home page" href="http://nant.sourceforge.net"><b>NAnt</b></a> <img src="../images/arrow.gif" alt="->" width="13" height="9" /> <a href="../index.html">Help</a> <img alt="->" src="../images/arrow.gif" /> <a href="index.html"> Fundamentals</a> <img height="9" alt="->" src="../images/arrow.gif" width="13" /> Build Files </td> <td class="NavBar-Cell" align="right"> v0.91 </td> </tr> </table> <h1>Build Files</h1> <p>NAnt's build files are written in XML. Each build file contains one <a href="projects.html"> project</a> and a number of <a href="targets.html">targets</a>. Each target contains a number of <a href="tasks.html">tasks</a>.</p> <p>Here is a simple build file that compiles a C# HelloWorld project. </p> <pre class="code"> <?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" failonerror="false" /> <delete file="HelloWorld.pdb" failonerror="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> </pre> <p>In this example there are two targets, "clean" and "build". By default the "build" target will be called. </p> <h3>Examples</h3> <p>You can find the files you need to try out these examples in the <code>examples</code> folder that comes with the NAnt distribution. </p> <blockquote dir="ltr" style="MARGIN-RIGHT: 0px"> <div><pre>nant</pre> </div> </blockquote> <p>Runs NAnt and builds the project in debug mode (the default).</p> <blockquote dir="ltr" style="MARGIN-RIGHT: 0px"> <div><pre>nant clean</pre> </div> </blockquote> <p>Runs NAnt and removes the compiled files if they exist.</p> <blockquote dir="ltr" style="MARGIN-RIGHT: 0px"> <div><pre>nant -D:debug=false</pre> </div> </blockquote> <p>Runs NAnt and builds the project in non-debug mode. Even though the build file sets the debug property to true, the value that is set on the command line will not be touched, as the "overwrite" attribute on the <code><a href="../tasks/property.html"><property></a></code> task is set to "false".</p> <p><strong>Important</strong>: Some tasks like the compiler tasks will only execute if the date stamp of the generated file is older than the source files. If you compile HelloWorld project in debug mode and then try to compile it again in non-debug mode without first cleaning nothing will happen because NAnt will think the project does not need rebuilding.</p> </body> </html>