Checks the conditional attributes and executes the children if true.
For a list of all members of this type, see IfTask Members.
System.Object
NAnt.Core.Element
NAnt.Core.Task
NAnt.Core.TaskContainer
NAnt.Core.Tasks.IfTask
NAnt.Core.Tasks.IfNotTask
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
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, TargetNameExists, PropertyNameExists, PropertyNameTrue, UpToDateFile.
Note instead of using the deprecated attributes, we advise you to use the following functions in combination with the Test attribute:
Function | Description |
---|---|
Exists | Checks whether the specified property exists. |
Exists | Checks whether the specified target exists. |
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>
Namespace: NAnt.Core.Tasks
Assembly: NAnt.Core (in NAnt.Core.dll)
IfTask Members | NAnt.Core.Tasks Namespace