Reputation: 12087
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>
Upvotes: 6
Views: 4602
Reputation: 2416
You can set a default property value and then an override if the condition is true:
<property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${deploy.env}\${app.dest.dir}\" />
<if test="${deploy.env == 'PROD'}">
<property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${app.dest.dir}\" />
</if>
Upvotes: 0
Reputation: 32212
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}\" />
Upvotes: 10