# <choose>

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

The <choose> task 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 `if`. 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

### Nested Elements:

#### <when>

One or more alternative sets of tasks to execute.

Groups a set of tasks to execute when a condition is met.

### Parameters

Attribute | Type | Description | Required
--- | --- | --- | ---
test | bool | Used to test arbitrary boolean expression. | True

#### </when>

#### <otherwise>

The set of tasks to execute if none of the When elements are true.

Executes embedded tasks/elements in the order in which they are defined.

#### </otherwise>

### 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 (0.92.4543.0)