NAnt:无法解析为布尔值

时间:2011-05-05 09:03:38

标签: if-statement nant type-conversion

<if test="${deployErrors} &gt; 0">
   <fail message="MSDeploy failed" />
</if>

${deployErrors}从正则表达式捕获组填充,并且具有数值或空字符串。如何在NAnt if块中检查是否大于0?如果部署错误包含'1'

,则会出现错误
  

'1&gt; 0'不是有效值   属性'test'。       无法解析'1&gt; 0'到布尔值。           字符串未被识别为有效的布尔值。

3 个答案:

答案 0 :(得分:8)

我没有尝试过,但我认为你需要在花括号内完整表达:

  

<if test="${deployErrors > 0}">

See also the second example in the documentation page.

从OP更新

这有效:

<if test="${deployErrors != ''}">

答案 1 :(得分:4)

如果您需要对实际数值做某事,那么您可以执行以下操作:

<if test="${int::parse('0' + deployErrors) > 10}">

答案 2 :(得分:0)

类似于Trystan的答案 - 将字符串解析为bool,对于字符串,例如truefalse

<if test="${bool::parse(isEnabled)}">

来自http://nant.sourceforge.net/release/0.85/help/functions/bool.parse.html