Configurable Builds: One configuration file per environment
One of the most important things when coding build files is to try and make them as configurable as possible.
At the very least on an agile project there will be a need for two different configurations - one for developer machines and one for continuous integration.
On my last two .NET projects we have setup our Nant build to take in a parameter which indicates which build configuration should be used. We then have a configuration file by that name which contains the environment specific data.
The build file would contain the following code before anything else:
<fail unless="${property::exists('environment')}" message="You must provide the environment property to the build script using -D:environment=[dev|ci]" />
<include buildfile="${trunk.dir}\config\${environment}.properties.xml" />
dev.properties.xml would look like this:
<?xml version="1.0" ?>
<properties>
<property name="property1" value="value1" />
<property name="property2" value="value2" />
</properties>
We would call the build file for the dev environment like so:
nant -buildfile:build-file.build target-name -D:environment=dev
Configuring the build this way assumes that the dev builds all have the same properties. On the projects where I used this approach this was the case.
The disadvantage of it is that you need to remember to pass in the environment variable each time you call the build. This can be countered by wrapping the full nant call in a batch script if it becomes too much of a hassle.
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.