| NAnt  Help  Fundamentals  Expressions | v0.85 | 
Expressions are simple, yet powerful mechanism that allows you to write advanced formulas to be used in task arguments and conditions that direct the build process. Expressions can access project properties and call builtin or user-defined functions.
NAnt provides a rich set of bulitin functions, that allow you to:
For a full list of supported functions, click here.
Expressions can be used in all task arguments, by using ${...} notation. 
            You may use standard syntax for arithmetical (addition, subtraction, 
            multiplication, division, modulus), logical (negation, conjunction, 
            alternative) and relational operators (equality, inequality). To call 
            functions, use prefix::function-name(argument1, ..., argumentN) syntax. 
            To access properties, you simply use their names without any prefix or suffix. 
            See the examples section below for more information.
NOTE: Expressions are often used in XML attributes. The grammar specified in this 
            section applies to the attribute value after XML 1.0 normalization. So, for 
            example, if the grammar uses the character <, this must not 
            appear in the XML source as < but must be quoted according to 
            XML 1.0 rules by, for example, entering it as <.
        
                    <property name="build.version" value="3" />
                    <echo message="The current date is:
                        ${build.version}" />
                
This will output the current value of build.version property.
                    <echo message="The current date is:
                        ${datetime::now()}" 
                        />
                
This will output the current date and time.
To store the result of an expression in a property, use the <property>
                    task:
                    <property name="autoexec-present" value="${file::exists('c:\autoexec.bat')}" 
                        />
                
This will set the property autoexec-present to either true
                    or false depending on whether the specified file exists or not.
                    <property name="myprj.basedir" value="c:\" />
                
                        <property name="filename" value="${path::combine(myprj.basedir,'version.txt')}" 
                        />
                        
                        <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>
 
This will check for the existence of a file version.txt in a directory specified by myprj.basedir. Note that this makes use of the short-circuit evaluation supported by NAnt, so you can test for the existence of the file and check its length in the same expression. ( ie like C, NAnt will not evaluate the second part of an 'or' expression if the first evaluates to true )
All tasks support if and unless attributes. 
                    Expressions can be used there to control which tasks get executed:
                    <property name="myprj.basedir" value="c:\" unless="property::exists('myprj.basedir')" 
                        />
                
                        <csc target="library" output="out.dll" ...
                        
                             if="${datetime::now() - file::get-last-write-time('out.dll')) > timespan::from-hours(1)}">
                        ...
                        </csc>
                    
This will rebuild the C# library only if it was last rebuilt more than an hour ago.
Expressions can access, pass and return values of the following types:
| Type | Allowed values | 
|---|---|
| int | 32-bit signed integer value | 
| long | 64-bit signed integer value | 
| double | 64-bit signed double precision floating point value | 
| boolean | true or false | 
| string | strings of characters of any length. | 
| datetime | values represeting date & time (range is from 00:00:00, January 1, 1 AD to 23:59:59, December 31, 9999 AD) | 
| timespan | represents a time interval. | 
In addition, the expression evaluation engine allows you to return and pass values of any CLI type through the use of custom functions. Note that there's no support for implicit type conversions.
NAnt expressions support standard ( c style ) operator precedence, that we're accustomed to:
and is evaluated before or, left to right. For 
                example false or true and true and false evaluates as false or 
                    ((true and true) and false)1 + 2 * 3 / 4 evaluates as 
                    1 + ((2 * 3) / 4)(1 + 2) * 3 evaluates as written, even though the 
                multiplication has precedence over additionNOTE: Because NAnt supports properties whose names can contain dashes, there's a possible ambiguity between the subtraction of two properties and accessing a single property with a name containing a dash:
        aaa-bbb - this is ambiguous. It could either be property aaa
            MINUS property bbb or property aaa-bbb.
To avoid confusion, it's recommended to surround the subtraction operator (or 
            even better, all binary operators) with spaces. The expression aaa - bbb
            always evaluates as a subtraction.
The following operators are supported on numeric values:
Returns the arithmetic sum of its operands.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 1 + 5evaluates to6 | 
| int | long | 1 + 6666666667evaluates to6666666668 | 
| int | double | 1 + 5.0evaluates to6.0 | 
| long | long | 6666666667 + 11111111111evaluates to17777777778 | 
| long | int | 6666666667 + 1evaluates to6666666668 | 
| long | double | 6666666667 + 1.5evaluates to6666666668.5 | 
| double | double | 1.5 + 5.0evaluates to6.5 | 
| double | int | 1.0 + 5evaluates to6.0 | 
| double | long | 1.5 + 6666666667evaluates to6666666668.5 | 
Returns the arithmetic difference of its operands.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 5 - 1evaluates to4 | 
| int | long | 5 - 6666666667evaluates to-6666666662 | 
| int | double | 5.0 - 1evaluates to4.0 | 
| long | long | 11111111111 - 6666666667evaluates to4444444444 | 
| long | int | 6666666667 - 5evaluates to6666666662 | 
| long | double | 6666666667 - 1.5evaluates to6666666665.5 | 
| double | double | 5.0 - 1.0evaluates to4.0 | 
| double | int | 5.0 - 1evaluates to4.0 | 
| double | long | 1.5 - 6666666667evaluates to-6666666665.5 | 
Returns the arithmetic product of its operands.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 5 * 2evaluates to10 | 
| int | long | 2 * 6666666667evaluates to13333333334 | 
| int | double | 5 * 2.0evaluates to10.0 | 
| long | long | 6666666667 * long::parse('2')evaluates to13333333334 | 
| long | int | 6666666667 * 2evaluates to13333333334 | 
| long | double | 6666666667 * 1.7evaluates to11333333333.9 | 
| double | double | 5.0 * 2.0evaluates to10.0 | 
| double | int | 5.0 * 2evaluates to10.0 | 
| double | long | 1.7 * 6666666667evaluates to11333333333.9 | 
Returns the arithmetic quotient of its operands.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 10 / 2evaluates to5 | 
| int | long | 10 / 10000000000evaluates to0.000000001 | 
| int | double | 8 / 2.0evaluates to4.0 | 
| long | long | 13333333334 / 6666666667evaluates to2 | 
| long | int | 13333333334 / 2evaluates to6666666667 | 
| long | double | 13333333334 / 2.0evaluates to6666666667.0 | 
| double | double | 9.0 / 2.0evaluates to4.5 | 
| double | int | 6.0 / 3evaluates to2.0 | 
| double | long | 20000000000.0 / 10000000000evaluates to2.0 | 
If the divisor is zero, then an error is raised.
Returns the remainder after dividing its first operand by its second.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 5 % 3evaluates to2 | 
| int | long | 10 % 6666666667evaluates to10 | 
| int | double | 5 % 3.5evaluates to1.5 | 
| long | long | 13333333334 % 6666666667evaluates to0 | 
| long | int | 6666666667 % 10evaluates to7 | 
| long | double | 6666666667 % 3.5evaluates to3.0 | 
| double | double | 9.0 % 4.7evaluates to4.3 | 
| double | int | 8.5 % 2evaluates to0.5 | 
| double | long | 20000000000.0 % 6666666667evaluates to6666666666.0 | 
If the divisor is zero, then an error is raised.
Returns true if and only if the value of the first operand is equal to the value of the second operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 5 == 3evaluates to false | 
| int | long | 5 == 6666666667evaluates to false | 
| int | double | 6 == 6.0evaluates to true | 
| long | long | 6666666667 == 6666666667evaluates to true | 
| long | int | 6666666667 == 665evaluates to false | 
| long | double | 6666666667 == 6666666667.0evaluates to true | 
| double | double | 9.5 == 6.7evaluates to false | 
| double | int | 8.5 == 8evaluates to false | 
| double | long | 8.5 == 6666666667evaluates to false | 
Returns true if and only if the value of the first operand is not equal to the value of the second operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 5 != 3evaluates to true | 
| int | long | 5 != 6666666667evaluates to true | 
| int | double | 6 != 6.0evaluates to false | 
| long | long | 6666666667 != 6666666667evaluates to false | 
| long | int | 6666666667 != 665evaluates to true | 
| long | double | 6666666667 != 6666666667.0evaluates to false | 
| double | double | 9.5 != 6.7evaluates to true | 
| double | int | 8.5 != 8evaluates to true | 
| double | long | 8.5 != 6666666667evaluates to true | 
Returns true if and only if the first operand is greater than the second operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 5 > 3evaluates to false | 
| int | long | 5 > 6666666667evaluates to false | 
| int | double | 6 > 4.0evaluates to true | 
| long | long | 6666666667 > 6666666667evaluates to false | 
| long | int | 6666666667 > 665evaluates to true | 
| long | double | 6666666667 > 6666666667.0evaluates to false | 
| double | double | 9.5 > 9.5evaluates to false | 
| double | int | 8.3 > 9evaluates to false | 
| double | long | 8.5 > 6666666667evaluates to false | 
Returns true if and only if the first operand is greater than or equal to second operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 5 >= 3evaluates to false | 
| int | long | 5 >= 6666666667evaluates to false | 
| int | double | 6 >= 4.0evaluates to true | 
| long | long | 6666666667 >= 6666666667evaluates to true | 
| long | int | 6666666667 >= 665evaluates to true | 
| long | double | 6666666667 >= 6666666667.0evaluates to true | 
| double | double | 9.5 >= 9.5evaluates to true | 
| double | int | 8.3 >= 9evaluates to false | 
| double | long | 8.5 >= 6666666667evaluates to false | 
Returns true if and only if the first operand is less than the second operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 5 < 3evaluates to false | 
| int | long | 5 < 6666666667evaluates to true | 
| int | double | 6 < 7.0evaluates to true | 
| long | long | 6666666667 < 6666666667evaluates to false | 
| long | int | 6666666667 < 665evaluates to false | 
| long | double | 6666666667 < 6666666667.0evaluates to false | 
| double | double | 9.5 < 9.5evaluates to false | 
| double | int | 8.3 < 9evaluates to true | 
| double | long | 8.5 < 6666666667evaluates to true | 
Returns true if and only if the first operand is less than or equal to second operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| int | int | 5 <= 3evaluates to false | 
| int | long | 5 <= 6666666667evaluates to true | 
| int | double | 6 <= 7.0evaluates to true | 
| long | long | 6666666667 <= 6666666667evaluates to true | 
| long | int | 6666666667 <= 665evaluates to false | 
| long | double | 6666666667 <= 6666666667.0evaluates to true | 
| double | double | 9.5 <= 9.5evaluates to true | 
| double | int | 8.3 <= 9evaluates to true | 
| double | long | 8.5 <= 6666666667evaluates to true | 
Returns its operand with the sign unchanged. Semantically, this operation performs no operation.
| Operand | Example | 
|---|---|
| int | (+1)evaluates to1 | 
| long | (+6666666667)evaluates to6666666667 | 
| double | (+1.5)evaluates to1.5 | 
Returns its operand with the sign reversed.
If the operand is positive, its negative is returned; if it is negative, its positive is returned.
| Operand | Example | 
|---|---|
| int | (-1)evaluates to-1 | 
| long | (-6666666667)evaluates to-6666666667 | 
| double | (-9.6)evaluates to-9.6 | 
The following operators are supported on boolean values:
Returns true if both operands are true or if both operands are false.
Returns true if the first operand is true and the second operand is false, or the first operand is false and the second operand is true.
Returns true if the first operand is true and the second operand is false; otherwise, returns false.
Returns true if the first operand is true and the second operand is false, or both operands are either true or false.
Returns true if the first operand is false and the second operand is true; otherwise, returns false.
Returns true if the first operand is false and the second operand is true, or both operands are either true or false.
Returns true if both operands are true, otherwise returns false.
        	<if test="${A and B}"> 
        	
        
Returns true if either operand is true, otherwise returns false.
        	<if test="${A or B}">        	
        
The following operators are supported on string values:
Returns the concatenation of both string operands.
Returns true if the value of the left operand is the same as the value of the right operand.
The comparison is case-sensitive and culture-insensitive.
Returns true if the value of the first operand is not the same as the value of the second operand.
The comparison is case-sensitive and culture-insensitive.
Returns true if the first operand is greater than the seconds operand.
The comparison is case-sensitive and culture-insensitive.
Returns true if the first operand is greater than or equal to the seconds operand.
The comparison is case-sensitive and culture-insensitive.
Returns true if the first operand is less than the seconds operand.
The comparison is case-sensitive and culture-insensitive.
Returns true if the first operand is less than or equal to the seconds operand.
The comparison is case-sensitive and culture-insensitive.
The following operators are supported on timespan and datetime values:
Returns the result of adding the value of the left operand to the value of the right operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| datetime | timespan | datetime::now() + timespan::from-days(10)evaluates to a datetime 10 days in the future | 
| timespan | timespan | timespan::from-seconds(30) + timespan::from-minutes(10)evaluates to a timespan representing a duratio of 10 minutes and 30 
                        seconds | 
Returns the result of subtracting the value of the right operand from the value of the left operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| datetime | datetime | (datetime::now() + timespan::from-days(10)) - datetime::nowevaluates to a timespan representing a duration of 10 days | 
| datetime | timespan | timespan::from-seconds(30) - timespan::from-seconds(10)evaluates 
                        to a timespan representing a duration of 20 seconds | 
| timespan | timespan | timespan::from-seconds(30) + timespan::from-minutes(10)evaluates 
                        to a timespan representing 10 minutes and 30 seconds | 
Returns true if the value of the left operand is the same as the value of the right operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| datetime | datetime | datetime::now() == (datetime::now()+timespan::from-days(10))evaluates 
                        to false | 
| timespan | timespan | timespan::from-seconds(30) == timespan::from-seconds(30)evaluates 
                        to true | 
Returns true if the value of the left operand is not the same as the value of the right operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| datetime | datetime | datetime::now() != (datetime::now()+timespan::from-days(10))evaluates 
                        to true | 
| timespan | timespan | timespan::from-seconds(30) != timespan::from-seconds(30)evaluates 
                        to false | 
Returns true if the value of the left operand is greater than the value of the right operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| datetime | datetime | datetime::now() > (datetime::now()+timespan::from-days(10))evaluates 
                        to false | 
| timespan | timespan | timespan::from-seconds(30) > timespan::from-seconds(30)evaluates 
                        to false | 
Returns true if the value of the left operand is greater than or equal to the value of the right operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| datetime | datetime | datetime::now() >= (datetime::now()+timespan::from-days(10))evaluates 
                        to false | 
| timespan | timespan | timespan::from-seconds(30) >= timespan::from-seconds(30)evaluates 
                        to false | 
Returns true if the value of the left operand is less than the value of the right operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| datetime | datetime | datetime::now() < (datetime::now()+timespan::from-days(10))evaluates 
                        to true | 
| timespan | timespan | timespan::from-seconds(30) < timespan::from-seconds(30)evaluates 
                        to false | 
Returns true if the value of the left operand is less than the value of the right operand.
| Left Operand | Right Operand | Example | 
|---|---|---|
| datetime | datetime | datetime::now() <= (datetime::now()+timespan::from-days(10))evaluates 
                        to false | 
| timespan | timespan | timespan::from-seconds(30) <= timespan::from-seconds(30)evaluates 
                        to true |