NAntScript Help Task Reference <taskdef> | v1.2.0 |
Creates a custom task containing NAnt tasks.
Define a task by specifying a name, a list of string parameters (attributes), and a lits of node parameters (child elements). A custom task is created that runs each of the tasks in the <do/> parameter replacing string parameters and node parameters before execution.
String parameters are referenced in the <do/> section using the syntax __parameter name__.
Node parameters are referenced in the <do/> section using the syntax <__parameter name__/>.
Attribute | Type | Description | Required |
---|---|---|---|
name | string | The name for the custom task. | True |
failonerror | bool | False | |
if | bool | False | |
unless | bool | False | |
verbose | bool | False |
Describes a string parameter to a custom scripted task.
Attribute | Type | Description | Required |
---|---|---|---|
name | string | The parameter name. | True |
required | bool | Specifies if the parameter is required (default is true) | False |
Describes an XML-Node parameter to a custom scripted task.
Attribute | Type | Description | Required |
---|---|---|---|
name | string | The parameter name. | True |
required | bool | Specifies if the parameter is required (default is true) | False |
Create a custom task that takes two parameters. Parameter 1 can be set to 'echo' or 'fail', and parameter 2 is the message to echo/fail.
<taskdef name="echoFail" > <stringparams> <stringparam name="task" /> <stringparam name="message" required="false" /> </stringparams> <do> <property name="customMessage" value="__message__" /> <if test="${customMessage == ''}" > <property name="customMessage" value="this is a default message" /> </if> <__task__ message="${customMessage}" /> </do> </taskdef> ... <!-- echos the default message --> <echoFail task="echo" /> ... <echoFail task="fail" message="this will fail the build" />
Create a custom task that takes a list of source files, target files, and a list of tasks to execute when the target files are not up to date.
<taskdef name="execIfNotUpToDate" > <nodeparams> <nodeparam name="sourceFiles" /> <nodeparam name="targetFiles" /> <nodeparam name="do" /> </nodeparams> <do> <uptodate property="execIfNotUpToDate.uptodate"> <sourcefiles> <__sourceFiles__/> </sourcefiles> <targetfiles> <__targetFiles__/> </targetfiles> </uptodate> <if test="${not execIfNotUpToDate.uptodate}" > <__do__/> </if> </do> </taskdef> ... <!-- echos the a message if the files are not up to date --> <execIfNotUpToDate> <sourceFiles> <include name="*.cs" /> </sourceFiles> <targetFiles> <include name="myAssembly.dll" /> </targetFiles> <do> <echo message="work needs done" /> </do> </execIfNotUpToDate>