<!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="Targets" /> <link rel="stylesheet" type="text/css" href="../style.css" /> <title>NAnt - Targets</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" /> Targets </td> <td class="NavBar-Cell" align="right"> v0.91 </td> </tr> </table> <h1>Targets</h1> <p>A target has these attributes:</p> <div class="table"> <table> <colgroup> <col /> <col /> <col style="text-align: center;" /> </colgroup> <tbody> <tr> <th> Attribute</th> <th> Description</th> <th> Required</th> </tr> <tr> <td>name</td> <td>The name of the target.</td> <td>Yes</td> </tr> <tr> <td>depends</td> <td>A comma-separated list of names of targets on which this target depends.</td> <td>No</td> </tr> <tr> <td>if</td> <td>An expression that should evaluate to <b>true</b> in order for this target to execute.</td> <td>No</td> </tr> <tr> <td>unless</td> <td>An expression that, when evaluated to <b>true</b>, will cause the target to be skipped.</td> <td>No</td> </tr> <tr> <td>description</td> <td>A short description of this target's function.</td> <td>No</td> </tr> </tbody> </table> </div> <p> The optional <code>description</code> attribute can be used to provide a one-line description of this target, which is printed by the <code style="whitespace: nowrap;"> -projecthelp</code> command-line option.</p> <h3><a id="dependencies" />Dependencies</h3> <p> A target can depend on other targets. You might have a target for compiling, for example, and a target for creating a distributable. You can only build a distributable when you have compiled first, so the distribute target <em>depends on</em> the compile target. NAnt resolves these dependencies.</p> <p> NAnt tries to execute the targets in the <code>depends</code> attribute in the order they appear from left to right. It is possible that a target can get executed earlier when an earlier target depends on it:</p> <pre class="code"> <target name="A"/> <target name="B" depends="A" /> <target name="C" depends="B" /> <target name="D" depends="C,B,A" /> </pre> <p> Suppose we want to execute target D. From its <code>depends</code> attribute, you might think that first target C, then B and then A is executed. Wrong! C depends on B, and B depends on A, so first A is executed, then B, then C, and finally D.</p> <p> A target gets executed only once, even when more than one target depends on it (see the previous example). However, when the <a href="../tasks/call.html"><call></a> task is used to execute a target, both the target and all its dependent targets will be re-executed.</p> <h3><a id="wild-targets" />Wild Targets</h3> <p> A target can be marked as <i>wild</i> by setting the <code>name</code> attribute to "*". A build file can contain up to one wild target, and it is executed if and only if the invoked target does not exist in the current build file. <i>Wild</i> targets let you define how to handle invalid requests, or provide generic behavior for unknown targets. For example:</p> <pre class="code"> <target name="A" /> <target name="B" /> <target name="*" /> </pre> <p> The last target is executed if the invoked target is neither A nor B.</p> <h3><a id="conditional-execution" />Conditional Execution</h3> <p> A target also has the ability to perform its execution if or unless a property has been set. This allows, for example, better control on the building process depending on the state of the system (OS, command-line property defines, etc.). To make a target <i>sense</i> this property, you should add the <code>if</code> or <code>unless</code> attribute with an expression that the target should react to. For example:</p> <pre class="code"> <target name="build-module-A" if="${module-A-present}" /> <target name="build-own-fake-module-A" unless="${file::exists('fake-module-a.dll')}" /> </pre> <p> If no <code>if</code> and no <code>unless</code> attribute is present, the target will always be executed.</p> <p><b>Note:</b> the dependencies of a target are always executed before testing the target's condition.</p> </body> </html>