andy
andy

Reputation: 8885

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?

Upvotes: 1

Views: 1072

Answers (2)

Josh M.
Josh M.

Reputation: 27821

You could simplify it to:

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

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

Upvotes: 0

andy
andy

Reputation: 8885

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>

Upvotes: 3

Related Questions