Question

In NAnt 0.92, I define a property and immediately after checks it's existence. It doesn't exists... but it exists in a called target. Is this a bug or a feature?!? I search in the documentation but could not find a mention of it.

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

Output:

test:

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

test2:

 [echo] property value in sub-target = test value
Was it helpful?

Solution

The name of the property needs to be quoted in your call to property::exists. So this is it:

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

Update: What does happen in your example? The unquoted property testprop is replaced by it's value in your call to function property::exists. So you're in fact probing property test value (which BTW isn't a valid property name). Check this out:

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

Output:

 [echo] property value = test.value
 [echo] property exists, as it should!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top