NAnt SDK Documentation - v0.92 |

# CallTask Class

Calls a NAnt target in the current project.

For a list of all members of this type, see CallTask Members.

System.Object
NAnt.Core.Element
NAnt.Core.Task
NAnt.Core.Tasks.CallTask

[Visual Basic]
<TaskName(Name:="call")>
Public Class CallTask
Inherits Task
[C#]
[TaskName(Name="call")]
public class CallTask : Task

#### Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

#### Remarks

When the 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 CascadeDependencies attribute on the CallTask to false (`recommended`).

#### Example

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 CascadeDependencies parameter of the 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 CascadeDependencies attribute of the 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

Namespace: NAnt.Core.Tasks

Assembly: NAnt.Core (in NAnt.Core.dll)

#### See Also

CallTask Members | NAnt.Core.Tasks Namespace