Is it possible to exclude a target from a NAnt build?

299 views Asked by At

I am looking for a way to tell NAnt not to execute a specified target. I've not found anything online so I'm not hopeful but perhaps the good people of SO can help.

The situation is: we have targets A, B, C, D, as well as an overall target T that calls all the others. A is independent of the others so is not really necessary; consider it a sort of an expensive sanity check.

I want to be able to run T and but exclude A - so it would only run B, C, D. Is this possible, or do I have to declare a new target to specifically run those jobs?

2

There are 2 answers

0
Alex On BEST ANSWER

@NotAgain's answer is useful if the target to be excluded is at the beginning or the end of the chain, but it does involve setting up a new target, or at least editing the existing one.

The best solution I've found so far is to use the conditional logic expressions. Example:

<property name="runThis" value="true" />
<target name="runIfPropTrue" if="${runThis}">
    <exec program="test.bat" />
</target>

This way you can set up any targets you may wish to exclude and switch them on and off by editing the property or by passing it in as a parameter instead. I assume you can use the unless expression just as easily but I haven't tested it.

1
NotAgain On

I am thinking in very simple way. You situation might be different.

I would have made T depend on B, C and D only.

When A is also needed I can call it in form of:

NAnt buildfile:Blah.build A T