4

在 NAnt 0.92 中,我定义了一个属性,并在检查它是否存在后立即进行。它不存在......但它存在于一个被调用的目标中。这是错误还是功能?!?我在文档中搜索,但找不到提及它。

<target name="test">
  <property name="testprop" value="test value" />

  <echo message="property value = ${testprop}" />

  <if test="${property::exists(testprop)}">
     <echo message="property exists, as it should!" />
  </if>

  <if test="${not property::exists(testprop)}">
     <echo message="property doesn't exists... WTF?" />
  </if>

  <call target="test2" />
</target>

<target name="test2">
  <echo message="property value in sub-target = ${testprop}" />
</target>

输出:

测试:

 [echo] property value = test value
 [echo] property doesn't exists... WTF?

测试2:

 [echo] property value in sub-target = test value
4

1 回答 1

5

在您对property::exists. 就是这样:

<if test="${not property::exists('testprop')}">
  <echo message="property doesn't exists... WTF?" />
  <!-- don't swear -->
</if>

更新:您的示例中发生了什么?在您对 function 的调用中,未引用的属性testprop将替换为它的值property::exists。所以你实际上是在探测属性test value(顺便说一句,它不是有效的属性名称)。看一下这个:

<target name="test">
  <property name="test.value" value="foo" />
  <property name="testprop" value="test.value" />
  <echo message="property value = ${testprop}" />
  <if test="${property::exists(testprop)}">
    <echo message="property exists, as it should!" />
  </if>
  <if test="${not property::exists(testprop)}">
    <echo message="property doesn't exists... WTF?" />
  </if>
</target>

输出:

 [echo] property value = test.value
 [echo] property exists, as it should!
于 2013-03-02T09:44:34.680 回答