I always have to look up how to do this, so I'm going to capture this now. If you ever need to make a NAnt script branch based on the machine it's running on, here's an easy way. First, go and get the machine name that the NAnt script is running on:
<property name="machine" value="${environment::get-machine-name()}" />
Then use the if and call tasks to call another target named after the machine:
<if test="${target::exists(machine)}">
<call target="${machine}"/>
</if>
Then simply create a separate task for each machine name like this:
<target name="TEST-SERVER">
<property name="database" value="invoice_test" />
</target>
<target name="PRODUCTION-SERVER">
<property name="database" value="invoice_prod" />
</target>
We use it occasionally in build scripts to handle differences in developer workstations (try not to do this though) and server environments without forking the build scripts.
Posted
Mon, Sep 11 2006 12:34 PM
by
Jeremy D. Miller