gpt4 book ai didi

NAnt property::exists() 具有新定义的属性?

转载 作者:行者123 更新时间:2023-12-02 04:28:01 27 4
gpt4 key购买 nike

在 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

最佳答案

在调用 property::exists 时需要引用属性名称。所以就是这样:

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

更新:您的示例中发生了什么?不带引号的属性 testprop 将被替换为调用函数 property::exists 时的值。因此,您实际上是在探测属性测试值(顺便说一句,这不是有效的属性名称)。看看这个:

<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!

关于NAnt property::exists() 具有新定义的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15168112/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com