Jeremy D. Miller -- The Shade Tree Developer

Sponsors

The Lounge

Wicked Cool Jobs

Syndication

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Machine specific tasks with NAnt

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

[Advertisement]

Comments

Jason Haley wrote Interesting Finds: September 11, 2006
on Mon, Sep 11 2006 9:27 PM
Jean-Francois Cantin wrote re: Machine specific tasks with NAnt
on Tue, Sep 12 2006 11:28 AM

you might want to look at Jean-Paul Boodhoo blog. He has a nice little trick with xml template file that does just that. So your nant file stays totally uncontaminated of machine specifics.

http://www.jpboodhoo.com/blog/AutomatingYourBuildsWithNAntPart6.aspx

-JF

Christopher Steen wrote Link Listing - September 12, 2006
on Tue, Sep 12 2006 9:17 PM

"Atlas" 1.0 Naming and Roadmap [Via: ScottGu ] BetaMarker.com - Early adopters welcome [Via: RoyOsherove...

Joshua Flanagan wrote re: Machine specific tasks with NAnt
on Tue, Sep 12 2006 10:30 PM

For additional reference/cross-training, I've posted an equivalent MSBuild script:

http://flimflan.com/blog/MachineSpecificTasksWithMSBuild.aspx

Jeremy D. Miller wrote re: Machine specific tasks with NAnt
on Wed, Sep 13 2006 8:49 AM

Josh & Jean-Francois, thanks for the tips.

paper machines wrote re: Machine specific tasks with NAnt
on Fri, Jun 20 2008 4:37 AM

I'm going to capture this now .

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Devlicio.us