在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?
TEST2:
[echo] property value in sub-target = test value
答案 0 :(得分:5)
在致电property::exists
时,需要引用该媒体资源的名称。所以就是这样:
<if test="${not property::exists('testprop')}">
<echo message="property doesn't exists... WTF?" />
<!-- don't swear -->
</if>
更新:您的示例中会发生什么?在您调用函数testprop
时,不带引号的属性property::exists
将替换为它的值。所以你实际上正在探测属性test value
(BTW不是有效的属性名称)。看看这个:
<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!