# <if>

[This is preliminary documentation and subject to change.]

Checks the conditional attributes and executes the children if true.

If no conditions are checked, all child tasks are executed.

If more than one attribute is used, they are &&'d. The first to fail stops the check.

The order of condition evaluation is, `targetexists`, `propertyexists`, `propertytrue`, `uptodatefile`.

Note: instead of using the deprecated attributes, we advise you to use the following functions in combination with the `test` attribute:

Function | Description
--- | ---
property::exists() | Checks whether the specified property exists.
target::exists() | Checks whether the specified target exists.

### Parameters

Attribute | Type | Description | Required
--- | --- | --- | ---
comparefile | string | Deprecated. The file to check against for the uptodate file. | False
propertyexists | string | Deprecated. Used to test whether a property exists. | False
propertytrue | string | Deprecated. Used to test whether a property is true. | False
targetexists | string | Deprecated. Used to test whether a target exists. | False
test | string | Used to test arbitrary boolean expression. | False
uptodatefile | string | Deprecated. The file to compare if uptodate. | 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 `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:

#### <comparefiles>

Deprecated. The <fileset> that contains the comparison files for the `uptodatefile`(s) check.

#### </comparefiles>

#### <uptodatefiles>

Deprecated. The <fileset> that contains the uptodate files for the `comparefile`(s) check.

#### </uptodatefiles>

### Examples

- Tests the value of a property using expressions.

      <if test="${build.configuration=='release'}">
          <echo>Build release configuration</echo>
      </if>

- Tests the the output of a function.

      <if test="${not file::exists(filename) or file::get-length(filename) = 0}">
          <echo message="The version file ${filename} doesn't exist or is empty!" />
      </if>

- `(Deprecated)` Check that a target exists.

      <target name="myTarget" />
      <if targetexists="myTarget">
          <echo message="myTarget exists" />
      </if>

- `(Deprecated)` Check existence of a property.

      <if propertyexists="myProp">
          <echo message="myProp Exists. Value='${myProp}'" />
      </if>

- `(Deprecated)` Check that a property value is true.

      <if propertytrue="myProp">
          <echo message="myProp is true. Value='${myProp}'" />
      </if>

- `(Deprecated)` Check that a property exists and is true (uses multiple conditions).

      <if propertyexists="myProp" propertytrue="myProp">
          <echo message="myProp is '${myProp}'" />
      </if>

  which is the same as

      <if propertyexists="myProp">
          <if propertytrue="myProp">
              <echo message="myProp is '${myProp}'" />
          </if>
      </if>

- `(Deprecated)` Check file dates. If `myfile.dll` is uptodate, then do stuff.

      <if uptodatefile="myfile.dll" comparefile="myfile.cs">
          <echo message="myfile.dll is newer/same-date as myfile.cs" />
      </if>

  or

      <if uptodatefile="myfile.dll">
          <comparefiles>
              <include name="*.cs" />
          </comparefiles>
          <echo message="myfile.dll is newer/same-date as myfile.cs" />
      </if>

  or

      <if>
          <uptodatefiles>
              <include name="myfile.dll" />
          </uptodatefiles>
          <comparefiles>
              <include name="*.cs" />
          </comparefiles>
          <echo message="myfile.dll is newer/same-date as myfile.cs" />
      </if>

### Requirements

Assembly: NAnt.Core (0.91.3881.0)