<call>

Calls a NAnt target in the current project.

When the NAnt.Core.Tasks.CallTask is used to execute a target, both that target and all its dependent targets will be re-executed.

To avoid dependent targets from being executed more than once, two options are available:

  • Add an "unless" attribute with value "${target::has-executed('<target name>')}" to the dependent targets.
  • Set the NAnt.Core.Tasks.CallTask.CascadeDependencies attribute on the NAnt.Core.Tasks.CallTask to false (recommended).

Parameters

Attribute Type Description Required
target string
NAnt target to call.
True
cascade bool
Execute the specified targets dependencies -- even if they have been previously executed. The default is true.
False
force bool
Force an execute even if the target has already been executed. The default is false.
Obsolete. Use the "cascase" attribute to control whether dependencies should be re-executed.
False
failonerror bool
Determines if task failure stops the build, or is just reported. The default is true.
False
if bool
If true then the task will be executed; otherwise, skipped. The default is true.
False
unless bool
Opposite of NAnt.Core.Task.IfDefined. If false then the task will be executed; otherwise, skipped. The default is false.
False
verbose bool
Determines whether the task should report detailed build log messages. The default is false.
False

Examples

Call the target "build".

<call target="build" />

This shows how a project could 'compile' a debug and release build using a common compile target.

    <project default="build">
    <property name="debug" value="false" />
    <target name="init">
        <echo message="initializing" />
    </target>
    <target name="compile" depends="init">
        <echo message="compiling with debug = ${debug}" />
    </target>
    <target name="build">
        <property name="debug" value="false" />
        <call target="compile" />
        <property name="debug" value="true" />
        <call target="compile" />
    </target>
</project>

The NAnt.Core.Tasks.CallTask.CascadeDependencies parameter of the NAnt.Core.Tasks.CallTask defaults to true, causing the "init" target to be executed for both the "debug" and "release" build.

This results in the following build log:

 build:
   
 init:

     [echo] initializing
     
 compile:
 
     [echo] compiling with debug = false
     
 init:
 
     [echo] initializing
     
 compile:
 
     [echo] compiling with debug = true
     
 BUILD SUCCEEDED

If the "init" should only be executed once, set the NAnt.Core.Tasks.CallTask.CascadeDependencies attribute of the NAnt.Core.Tasks.CallTask to false.

The build log would then look like this:

 build:
   
 init:

     [echo] initializing
     
 compile:
 
     [echo] compiling with debug = false
     
 compile:
 
     [echo] compiling with debug = true
     
 BUILD SUCCEEDED

Requirements

Assembly
NAnt.Core.dll
Namespace
NAnt.Core.Tasks