Configurable Builds: Overriding properties
In these cases we can just override properties when we call Nant from the command line.
One recent example where I made use of this was where we had one configuration file with properties in but wanted to override a couple of them when we ran the continuous integration build.
Since build properties are immutable (i.e. once they are set they can’t be changed) if we set them from the command line the build script makes use of these values.
For example we might have the following in our build file:
<property name="repository.url" value="http://localhost:3000" />
But when we’re running it on cruise control we have the repository on a different machine. We can override it like so:
nant -buildfile:build-file.build target-name -D:repository.url=http://some-remote-url
If we have more than one property we want to override it might be a bit annoying to have to pass them all via the command line. We can define them in a file to overcome this problem:
nant -buildfile:build-file.build target-name @ci.properties.xml
where ci.properties.xml contains the following:
If you start seeing a lot of properties in this file then it is probably an indicator that you need to have a more robust solution but this works for providing simple flexibility.