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

I have a NAnt <exec> task. I want one argument to be conditional on some true property.

For example, I want the -c psExec command line argument to be conditional. It should be displayed 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 produces 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?

+7
source share
2 answers

Properties in NAnt are complex because they are not of type and are simply treated as a type of string . So this will 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}" also works. Thus, there is a typical typification of properties.

+5
source

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

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

Comparing the boolean expression true with true does not change the result.

+2
source

All Articles