IfTask Class

Summary

Checks the conditional attributes and executes the children if true.
Assembly
NAnt.Core.dll
Namespace
NAnt.Core.Tasks
Interfaces
Base Types
Derived Types
graph BT Type-->Base0["TaskContainer"] click Base0 "/api/NAnt.Core/TaskContainer" Base0-->Base1["Task"] click Base1 "/api/NAnt.Core/Task" Base1-->Base2["Element"] click Base2 "/api/NAnt.Core/Element" Base2-->Base3["Object"] Type-.->Interface0["IConditional"] click Interface0 "/api/NAnt.Core/IConditional" Type["IfTask"] class Type type-node Derived0["IfNotTask"]-->Type click Derived0 "/api/NAnt.Core.Tasks/IfNotTask"

Syntax

[TaskName("if")]
public class IfTask : TaskContainer, IConditional

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>

Remarks

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, NAnt.Core.Tasks.IfTask.TargetNameExists, NAnt.Core.Tasks.IfTask.PropertyNameExists, NAnt.Core.Tasks.IfTask.PropertyNameTrue, NAnt.Core.Tasks.IfTask.UpToDateFile.

instead of using the deprecated attributes, we advise you to use the following functions in combination with the NAnt.Core.Tasks.IfTask.Test attribute:
DescriptionChecks whether the specified property exists.Checks whether the specified target exists.
Function
NAnt.Core.Functions.PropertyFunctions.Exists(System.String)
NAnt.Core.Functions.TargetFunctions.Exists(System.String)

Attributes

Type Description
TaskNameAttribute Indicates that class should be treated as a task.

Properties

Name Value Summary
CompareFile string
The file to check against for the uptodate file.
CompareFiles FileSet
The NAnt.Core.Types.FileSet that contains the comparison files for the NAnt.Core.Tasks.IfTask.UpToDateFile(s) check.
ConditionsTrue bool
CustomXmlProcessing bool
Gets a value indicating whether the element is performing additional processing using the System.Xml.XmlNode that was use to initialize the element.
Inherited from TaskContainer
FailOnError bool
Determines if task failure stops the build, or is just reported. The default is true.
Inherited from Task
IfDefined bool
If true then the task will be executed; otherwise, skipped. The default is true.
Inherited from Task
Location Location
Gets or sets the location in the build file where the element is defined.
Inherited from Element
LogPrefix string
The prefix used when sending messages to the log.
Inherited from Task
Name string
The name of the task.
Inherited from Task
NamespaceManager XmlNamespaceManager
Gets or sets the System.Xml.XmlNamespaceManager.
Inherited from Element
Parent Object
Gets or sets the parent of the element.
Inherited from Element
Project Project
Gets or sets the NAnt.Core.Element.Project to which this element belongs.
Inherited from Element
Properties PropertyDictionary
Gets the properties local to this NAnt.Core.Element and the NAnt.Core.Element.Project.
Inherited from Element
PropertyNameExists string
Used to test whether a property exists.
PropertyNameTrue string
Used to test whether a property is true.
TargetNameExists string
Used to test whether a target exists.
Test string
Used to test arbitrary boolean expression.
Threshold Level
Gets or sets the log threshold for this NAnt.Core.Task. By default the threshold of a task is NAnt.Core.Level.Debug, causing no messages to be filtered in the task itself.
Inherited from Task
UnlessDefined bool
Opposite of NAnt.Core.Task.IfDefined. If false then the task will be executed; otherwise, skipped. The default is false.
Inherited from Task
UpToDateFile string
The file to compare if uptodate.
UpToDateFiles FileSet
The NAnt.Core.Types.FileSet that contains the uptodate files for the NAnt.Core.Tasks.IfTask.CompareFile(s) check.
Verbose bool
Determines whether the task should report detailed build log messages. The default is false.
Inherited from Task
XmlNode XmlNode
Gets or sets the XML node of the element.
Inherited from Element

Methods

Name Value Summary
AddPrivateXmlElementName(string) void
Inherited from TaskContainer
CopyTo(Element) void
Copies all instance data of the NAnt.Core.Element to a given NAnt.Core.Element.
Inherited from Element
CreateChildDataTypeBase(XmlNode) DataTypeBase
Inherited from TaskContainer
CreateChildTask(XmlNode) Task
Inherited from TaskContainer
Execute() void
Executes the task unless it is skipped.
Inherited from Task
ExecuteChildTasks() void
Creates and executes the embedded (child XML nodes) elements.
Inherited from TaskContainer
ExecuteTask() void
Executes the task.
GetAttributeConfigurationNode(FrameworkInfo, string) XmlNode
Locates the XML node for the specified attribute in either the configuration section of the extension assembly or the.project.
Inherited from Task
GetAttributeConfigurationNode(XmlNode, FrameworkInfo, string) XmlNode
Inherited from Element
GetLocation() Location
Retrieves the location in the build file where the element is defined.
Inherited from Element
Initialize() void
Automatically exclude build elements that are defined on the task from things that get executed, as they are evaluated normally during XML task initialization.
Initialize(XmlNode) void
Performs default initialization.
Inherited from Element
InitializeBuildElement(Element, XmlNode, Element, Type) Element
Initializes the build element.
Inherited from Element
static
InitializeElement(XmlNode) void
Derived classes should override to this method to provide extra initialization and validation not covered by the base class.
Inherited from Element
InitializeTask(XmlNode) void
Initializes the task.
Inherited from Task
InitializeTaskConfiguration() void
Initializes the configuration of the task using configuration settings retrieved from the NAnt configuration file.
Inherited from Task
InitializeXml(XmlNode, PropertyDictionary, FrameworkInfo) void
Initializes all build attributes and child elements.
Inherited from Element
IsLogEnabledFor(Level) bool
Determines whether build output is enabled for the given NAnt.Core.Level.
Inherited from Task
IsPrivateXmlElement(XmlNode) bool
Inherited from TaskContainer
Log(Level, string) void
Logs a message with the given priority.
Inherited from Task
Log(Level, string, Object[]) void
Logs a formatted message with the given priority.
Inherited from Task