82 lines
4.1 KiB
HTML
Raw Normal View History

<!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="-&gt;" width="13" height="9" />
<a href="../index.html">Help</a> <img alt="-&gt;" src="../images/arrow.gif" /> <a href="index.html">
Fundamentals</a> <img height="9" alt="-&gt;" 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>&nbsp;and a number of <a href="targets.html">targets</a>.&nbsp;
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.&nbsp;
</p>
<pre class="code">
&lt;?xml version="1.0"?&gt;
&lt;project name="Hello World" default="build" basedir="."&gt;
&lt;description&gt;The Hello World of build files.&lt;/description&gt;
&lt;property name="debug" value="true" overwrite="false" /&gt;
&lt;target name="clean" description="remove all generated files"&gt;
&lt;delete file="HelloWorld.exe" failonerror="false" /&gt;
&lt;delete file="HelloWorld.pdb" failonerror="false" /&gt;
&lt;/target&gt;
&lt;target name="build" description="compiles the source code"&gt;
&lt;csc target="exe" output="HelloWorld.exe" debug="${debug}"&gt;
&lt;sources&gt;
&lt;includes name="HelloWorld.cs" /&gt;
&lt;/sources&gt;
&lt;/csc&gt;
&lt;/target&gt;
&lt;/project&gt;
</pre>
<p>In this example there are two targets, "clean" and "build".&nbsp; 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.&nbsp; 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">&lt;property&gt;</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.&nbsp;
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>