Say I have two XML build files. The first is intended to call a target in the second.
Example1.xml:
.cf { font-family: Courier New; font-size: 8pt; color: black; background: white; } .cl { margin: 0px; } .cln { color: #2b91af; } .cb1 { color: blue; } .cb2 { color: #a31515; } .cb3 { color: red; }
1 <?xml version="1.0"?>
2 <project name="Master build file" default="build" basedir=".">
3
4 <echo message="first" />
5
6 <include buildfile="example2.xml" />
7
8 <target name="build" description="Main target">
9 <echo message="second" />
10 <call target="secondary.target" />
11 </target>
12 </project>
Example2.xml:
.cf { font-family: Courier New; font-size: 8pt; color: black; background: white; } .cl { margin: 0px; } .cln { color: #2b91af; } .cb1 { color: blue; } .cb2 { color: #a31515; } .cb3 { color: red; }
1 <?xml version="1.0"?>
2
3 <target name="secondary.target">
4 <echo message="third" />
5 </target>
I had expect that the secondary.target target would not be called until after the build target was called. Instead:
.cf { font-family: Courier New; font-size: 8pt; color: black; background: white; } .cl { margin: 0px; }
NAnt 0.85 (Build 0.85.2478.0; release; 14/10/2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net
Buildfile: file:///C:/Inetpub/virtual2005/Projects/Canon/CanonCreate2005/example1.xml
Target framework: Microsoft .NET Framework 2.0
Target(s) specified: build
[echo] first
[echo] third
build:
[echo] second
BUILD FAILED
Target 'secondary.target' does not exist in this project.
Total time: 0 seconds.
Huh? Why did the output go “first”, “third”, then “second”? And why does it say secondary.target doesn’t exist?
The documentation for the <include> task states:
Any global (project level) tasks in the included build file are executed when this task is executed. Tasks in target elements are only executed if that target is executed.
Which means my build file should be executing correctly. It’s in a target, isn’t it?
So I tried wrapping the secondary target in a project tag, and lo and behold:
.cf { font-family: Courier New; font-size: 8pt; color: black; background: white; } .cl { margin: 0px; }
NAnt 0.85 (Build 0.85.2478.0; release; 14/10/2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net
Buildfile: file:///C:/Inetpub/virtual2005/Projects/Canon/CanonCreate2005/example1.xml
Target framework: Microsoft .NET Framework 2.0
Target(s) specified: build
[echo] first
build:
[echo] second
secondary.target:
[echo] third
BUILD SUCCEEDED
Total time: 0 seconds.
So the NAnt docs aren’t entirely complete, are they. So I suppose the tag <project> is really a way of saying “this is build script which I want to control the execution for, instead of just processing the whole file as NAnt reads it”.