【问题标题】:What does it mean for a property to "exist" in NAnt?属性在 NAnt 中“存在”意味着什么?
【发布时间】:2014-11-26 15:30:40
【问题描述】:

谁能解释在南特“存在”属性意味着什么?我对以下构建脚本有一些奇怪的行为:

<?xml version="1.0" encoding="utf-8" ?>
<project name="Test.Project" default="doIt">
  <!-- property name="test.prop" value="OK" / -->

  <target name="doIt">
    <if test="${property::exists ('test.prop')}">
        <echo>Before ${test.prop}</echo>
    </if>

    <foreach item="String" in="1,2,3" delim="," property="test.prop">
        <echo>${test.prop}</echo>
    </foreach>

    <if test="${property::exists ('test.prop')}">
        <echo>After ${test.prop}</echo>
    </if>
  </target>
</project>

定义test.prop 会导致预期的“Before OK”、“1”、“2”、“3”、“After OK”回声序列,但是如果 test.prop 在开始时没有定义(如上面的代码),我得到“1”,“2”,“3”,然后出现以下错误:

Property evaluation failed.
Expression: After ${test.prop}
                    ^^^^^^^^^
    Property 'test.prop' has not been set.

即该属性通过了property::exists 测试,但随后表现得好像它应该失败了。

这是 NAnt 中的错误,还是我实际上应该使用 property::exists 以外的其他测试来确定在 &lt;foreach&gt; 中使用某个属性后我是否可以访问它?

[我在 NAnt 0.90 中发现了这一点,但更新到 NAnt 0.92 具有相同的行为]

【问题讨论】:

  • FWIW,在 0.85 也确认了同样的行为。
  • 我会说这可能是一个错误,可能在foreachIt specifies“属性值在循环完成之前存储,并在循环完成时恢复。属性一旦使用就会返回到正常值” - 所以它恢复为没有值,但不是不存在,这是有道理的 - 它现在已定义(foreach 任务做到了),但没有任何价值,因为它是在任务运行之前“设置”的
  • 是的,我假设 中有一个错误,尽管我也认为 properties::exists 未能满足其隐含合同,即如果您通过了 properties::exists 测试那么您不应该收到“尚未设置”错误!
  • 是的,property::exists 可能应该进行某种“可空性”检查,如果任务(可能是其他程序集中的第 3 方任务)可能导致属性进入此状态。跨度>
  • 我没有考虑过第 3 方任务;仅仅修复&lt;foreach&gt; 的行为是不够的:-(

标签: nant


【解决方案1】:

看起来答案就在 cmets 中:可能是 &lt;foreach&gt; 中的一个错误

【讨论】:

    猜你喜欢
    • 2011-01-17
    • 2017-12-10
    • 2019-05-03
    • 2015-12-24
    • 2018-05-29
    • 2015-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多