tags:

views:

209

answers:

2

I have a generic common.xml file that holds a number of generic nant targets that are re-used among multiple builds. What I want to do is 'override' some of these nant targets and include additional steps either before or after the existing target is executed.

Are nant targets used from the current file first? ie. If i create a nant target in the current buildfile with the same name as a target in an included file does that one get called and the included one ignored? If that's the case I can just do and call the included target but it would seem like then that would be a recursive call rather then to an included task.

Thoughts?

+1  A: 

No, I've just tried it for you, as I have a similar set-up, in that I have all of the build targets we use in a commonFile.build and then use the following code to bring it in...

<include buildfile="../commonFile.build"/>

In my newFile.build (that includes the commonFile.build at the top of the file), I added a new target called 'build', as it exists in the commonFile, and here's the error message you get in response...

BUILD FAILED

Duplicate target named 'build'!

Nice idea, probably bourne of OO principles, but sadly it doesn't work.

Any good?

Brett Rigby
A: 

I had the same question (and found the same results), but I also found a workaround. Allow me to illustrate with an example.

You have a ProjectFile.build and a CommonFile.build. Let's say you want to overwrite a target called "Clean".

You would need to create a new file (call it CommonFile_Clean.build) which contains:

<?xml version="1.0"?>
<project>
  <target name="Clean">
        <echo message="Do clean stuff here" />
  </target>
</project>

In CommonFile.build, you conditionally include CommonFile_Clean.build:

<?xml version="1.0"?>
<project>
    <echo message="checking Clean definition..." />
    <if test="${not target::exists('Clean')}">
            <echo message="Clean target not defined." />
        <include buildfile="CommonFile_Clean.build" />      
    </if>
</project>

In ProjectFile.build, you can either define the Clean target (in which case CommonFile_Clean.build will not be used) or use the default implementation as defined in CommonFile_Clean.build.

Of course, if you have a large number of targets, this will be quite a bit of work.

Hope that helps.

FlyingSheep