In NAnt <exec>, how to have a conditional <arg> based on property value?
Asked Answered
O

2

8

I've got an NAnt <exec> task. I want one argument presence to be conditional to some property being true.

For example, I want the -c command line argument of psExec to be conditional. It should be outputted only if ${pExec.copyprog == 'true'}.

The following does not work:

<property name="psExec.copyprog" value="false" />
...

<exec program="${psExec.path}" failonerror="false">
   ...
   <arg line="-c" if="${psExec.copyprog}==true" />
</exec>

It yields the following error:

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

How can I achieve this?

Oto answered 1/3, 2013 at 22:4 Comment(0)
M
6

Properties in NAnt are tricky since they don't have a type and simply are considered as of type string. So this would be the solution:

<exec program="${psExec.path}" failonerror="false">
  <!-- ... -->
  <arg line="-c" if="${bool::parse(psExec.copyprog)}" />
</exec>

Update: Mea culpa! I was wrong. if="${psExec.copyprog}" does also work. So there is some sort of property typing.

Mcgrath answered 2/3, 2013 at 6:50 Comment(0)
A
3

You'd need to put ==true inside {}, but you can also just skip it:

<arg line="-c" if="${psExec.copyprog}" />  

Comparing a true boolean expression to true does not change the result.

Apteral answered 3/3, 2013 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.