Evaluating property equality in Nant
Asked Answered
A

3

7

In my Nant script I would like to compare a property value to a known string. After reading the Nant Expressions documentation I believed I would be able to do a basic '==' comparison to evaluate as a boolean.

However given the script block:

<if test="${target.env} == Dev">
  <echo message="***** You are using DEV"/>
</if>

When executed I recieve the following error:

'Dev == Dev' is not a valid value for attribute 'test' of <if ... />.
    Cannot resolve 'Dev == Dev' to boolean value.
    String was not recognized as a valid Boolean.

This seems as though it should be simple (and probably is). How do I compare two strings, or properties in Nant to evaluate as a boolean?

Aestivation answered 30/4, 2009 at 23:57 Comment(0)
B
11

See here for example. e.g.

<if test="${target.env}=='Dev'">
    ....
</if>
Basidiomycete answered 1/5, 2009 at 0:1 Comment(2)
beautiful. i knew it would be easy!Aestivation
For me this is what worked <if test="${target.env=='Dev'}">Evelynneven
G
18

It also works if you have the entire expression within the curly braces:

<if test="${target.env =='Dev'}">
    ....
</if>
Geometrid answered 13/5, 2009 at 15:44 Comment(2)
This way also works if you're comparing to an empty string (e.g. <if test="${target.env == ''}"> ), where-as the top version doesn'tBarbabas
There must be mentioned that for >= < etc. you have to use <if test=“${int::parse(intValue) > 123}“>, explained in #915929.Selry
B
11

See here for example. e.g.

<if test="${target.env}=='Dev'">
    ....
</if>
Basidiomycete answered 1/5, 2009 at 0:1 Comment(2)
beautiful. i knew it would be easy!Aestivation
For me this is what worked <if test="${target.env=='Dev'}">Evelynneven
D
5

if you want to compare two variables ${test.var1} and ${test.var2} then

<if test="${test.var1 == test.var2}">
....
</if>
Dermatogen answered 20/10, 2010 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.