Swingnchad’s Blog

Just another WordPress.com weblog

Using NAnt with an external remote server

Posted by swingnchad on June 23, 2009

Problem

I was tasked to create our first build script for our website www.namesinstone.com  One major problem was using Nant with an external production server.  It was ok to get it to build our website, build  the unit tests, then copy the built files to our internal dev server (nant doesn’t copy .svn files).  I couldn’t find any options to copy the files to an external server, let alone copy them securely over the internet.  I tried the putty suite – plink and pscp which I almost got working with private and public keys, but never completly got it how I wanted.  My goal was to:

  1. Zip our website up locally
  2. Copy it from our test server to our production server securely over the internet
  3. Unzip it on the server.
  4. Then copy the contents to the web site dir.

With pscp.exe I was able to upload the zip.  But trying to get plink to unzip it on the external server and copy the files to a new location was painful.  After a couple days I gave up.

Solution

Now comes WCF…  If you are familiar with creating WCF services, save yourself the time and implement your own like I did.  If you’re not familiar with creating WCF’s, read this article and you’re on track.  Either way, spending time learning how to create WCF services is way more productive than fighting with pscp and Nant.  Here’s how I have it setup now:

  1. Cruise Control runs Nant script (btw, I use 3 different nant scripts each for dev, test, and prod)
  2. Nant script executes my WCF console app client passing in 3 arguments: location of the zip file, environment (dev, test, prod) and -batch (to suppress all console.writeline()’s).
  3. from there, the WCF client makes call to the WCF service to copy the zip file via a byte array.
  4. The service then unzips the file using DotNetZip.  (.net doesn’t have zip functionality built in)
  5. The service copies the uncompressed files to the target website dir.

Conclusion

Writing the service and client only took a couple days including integrating it with the already created nant script.  On top of that, WCF uses wshttp bindings which adds the security when transfering files.  A couple pain in the butt gotcha’s you should watch out for when transfering files using WCF:

  1. The web.config of your WCF service needs to set various attributes to transfer files larget than 50KB. 
  2. Make sure the web.config contains the setting to overwrite the IIS 4MB limit if your zip is bigger than that.
  3. No changes need to be made to the app.config of the client.  Only web.config changes affect file transfer (from what I’ve experienced anyway)
  4. Make sure the client and WCF service are different projects but part of the same solution so you can right click on the client project and choose “Add Service Reference”.

With a lot of google searching and a lot of luck, you’ll get it working.  One more thing to get you motivated: now that it’s all setup it’s pretty slick.  I just have to open the Cruise Control Dashboard web page, click on one of my builds (Dev, Test, or Prod), then click the Force button to start the deployment process.  Sit back and watch the magic happen.  Now we have a one click solution to deploy from test to prod!  Very nice indeed!  And with the cctray.exe it makes it even nicer (not to mention Ncover).  I’m starting to like this build script thing, but boy it’s a pain in the rear to get working.  Some day it’ll get easier… some day…

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>