The McDev Blog

Kevin McKelvin's perspective of the Ruby world.

Powershell Builds With Psake

James Kovacs released Psake (pronounced sake, as in Japanese rice wine) – a Powershell based DSL for automated builds.

After source control, the next most important step of infrastructure is a one step build process. You should ideally have a scheduled build that begins with a clean checkout of your code from your version control server and does a build of every configuration of your software that will be delivered to customers. This includes localizations, trial versions and alternate build configurations (using #if/endif). Your unit tests should also be run as part of the build and the results must be made available.

We had been using the Ruby Rake build system for a year now, but the dependency on Ruby has always been a downfall because of Ruby’s boot up time on Windows. Removing my dependency on Ruby was the main motivation that I’ve swapped all of my builds over to using Powershell and Psake.

What I love the most is the clarity of the script, here’s a sample of the compile task in a build script.

task Default -depends Compile
task Init { ... }
task Compile -depends Init {
  & msbuild "$proj_file" "/p:OutDir=$build_dir\\" /p:Configuration=Release   
  if ($lastExitCode -ne 0) {
     throw "Error: Failed to execute msbuild"

Much nicer than the XML used for NAnt builds!

In Rake you have access to the Ruby backend, with Psake you have the whole of Powershell to work with. Best of all it integrates pretty seamlessly with build servers such as TeamCity and Hudson.