<choose>

Executes an alternate set of task or type definition depending on conditions that are individually set on each group.

The NAnt.Core.Tasks.ChooseTask selects one among a number of possible alternatives. It consists of a sequence of <when> elements followed by an optional <otherwise> element.

Each <when> element has a single attribute, test, which specifies an expression. The content of the <when> and <otherwise> elements is a set of nested tasks.

The content of the first, and only the first, <when> element whose test is true is executed. If no <when> element is true, the content of the <otherwise> element is executed. If no <when> element is true, and no <otherwise> element is present, nothing is done.

Parameters

Attribute Type Description Required
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

Execute alternate set of tasks depending on the configuration being built.

    <choose>
    <when test="${build.config == 'Debug'}">
        <!-- compile app in debug configuration -->
        ...
    </when>
    <when test="${build.config == 'Release'}">
        <!-- compile app in release configuration -->
        ...
    </when>
    <otherwise>
        <fail>Build configuration '${build.config}' is not supported!</fail>
    </otherwise>
</choose>

Define a sources patternset holding an alternate set of patterns depending on the configuration being built.

    <choose>
    <when test="${build.config == 'Debug'}">
        <patternset id="sources">
            <include name="**/*.cs" />
        </patternset>
    </when>
    <when test="${build.config == 'Release'}">
        <patternset id="sources">
            <include name="**/*.cs" />
            <exclude name="**/Instrumentation/*.cs" />
        </patternset>
    </when>
    <otherwise>
        <fail>Build configuration '${build.config}' is not supported!</fail>
    </otherwise>
</choose>

Requirements

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