Let's assume you have a large build file with many-many targets, properties, etc. After some time it becomes pretty hard to support and extend it. What can we do? As for me, the best option here is to split your build file to several pieces. Below goes an example on how you can do this.
My default.build file:
<?xml version="1.0"?>build.include file:
<project name="NAnt HowTo 2" default="all" xmlns="http://nant.sf.net/release/0.85-rc2/nant.xsd">
<!-- Includes -->
<include buildfile="build.include" />
<include buildfile="test.include" />
<target name="all" description="Default target, calls all deployment tasks.">
<call target="rebuild" />
<call target="test" />
</target>
<target name="rebuild" descripton="Rebuilds all projects." >
<call target="clean" />
<call target="build" />
</target>
<target name="test" description="Runs all tests.">
<call target="tests.unit.run" />
<call target="tests.integration.run" />
</target>
</project>
<project xmlns="http://nant.sf.net/release/0.85-rc2/nant.xsd">test.include file:
<target name="clean">
<echo message="Rebuild: clean" />
</target>
<target name="build">
<echo message="Rebuild: build" />
</target>
</project>
<project xmlns="http://nant.sf.net/release/0.85-rc2/nant.xsd">
<target name="tests.unit.run">As you can see, actual inclusion takes place when you use <include> element and specify it's buildfile attribute to point to some .include file.
<echo message="Test: unit tests" />
</target>
<target name="tests.integration.run">
<echo message="Test: integration tests" />
</target>
</project>
.include files should contain root <project xmlns="http://nant.sf.net/release/0.85-rc2/nant.xsd"> element with necessary xmlns attribute. Without this attribute NAnt won't be able to parse this file and use it's targets.
Included files become a piece of main build file and share all properties with it. This means that properties from included file are visible in main file and vise-versa. I usually place commonly used properties to separate .include files, for example, I have projects.include file with all properties that point to project names and folders.