Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do an IF/ELSE in NANT 0.91?

Tags:

nant

We're using Nant 0.91 so <choose> is not available. How would you do an IF/ELSE in Nant 0.91? I would like to do something like (using NAnt 0.92 syntax) in NAnt 0.91. [I am not allowed to modify the current installation of NAnt 0.91]:

<choose>
   <when test="${deploy.env=='PROD'}">
        <property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${app.dest.dir}\" />
    </when>
    <otherwise>
        <property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${deploy.env}\${app.dest.dir}\" />
    </otherwise>
</choose>
like image 232
Denis Avatar asked Sep 22 '15 14:09

Denis


1 Answers

The simplest solution, which we use here, is to just use two if tasks, one with a negative test to the other:

<if test="${deploy.env == 'PROD'}">
    <property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${app.dest.dir}\" />
</if>
<if test="${deploy.env != 'PROD'}">
    <property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${deploy.env}\${app.dest.dir}\" />
</if>

However in your case, you can also make use of the fact that the property task has inbuilt if/unless functionality:

<property name="deploy.root.dir" if="${deploy.env == 'PROD'}" value="\\${deploy.server}\${deploy.mode}\${app.dest.dir}\" />
<property name="deploy.root.dir" unless="${deploy.env == 'PROD'}" value="\\${deploy.server}\${deploy.mode}\${deploy.env}\${app.dest.dir}\" />
like image 178
James Thorpe Avatar answered Sep 21 '22 13:09

James Thorpe