NAnt SDK Documentation - v0.92 |

# ChooseTask Class

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

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

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

[Visual Basic]
<TaskName(Name:="choose")>
Public Class ChooseTask
Inherits Task
[C#]
[TaskName(Name="choose")]
public class ChooseTask : 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

The 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.

#### Example

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

Namespace: NAnt.Core.Tasks

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

#### See Also

ChooseTask Members | NAnt.Core.Tasks Namespace