Search code examples
nant

Check if a target exists dynamically using Nant?


According to the Nant documentation, you can check if a target exists using the target::exists function.

Execute target "clean", if it exists.

<if test="${target::exists('clean')}">
<call target="clean" />
</if>

I've tried passing in the name of the target as a property and it doesn't seem to work.

Nant doesn't throw an error, but neither does it return true, when it should.

Essentially what I'm trying to do is this:

<property name="cleanTarget" value="${someothervariables}"/>

<if test="${target::exists('${cleanTarget}')}">
<call target="${cleanTarget}" />
</if>

Is it possible?


Solution

  • I worked it out, my syntax was wrong.

    The correct way would be:

    <property name="cleanTarget" value="${someothervariables}"/>
    
    <if test="${target::exists(cleanTarget)}">
    <call target="${cleanTarget}" />
    </if>