Getting started with rake on .NET and visual studio

Rake is normally used as a build tool scripting language (if used for anything else, please do comment). I’ve been using it for almost 2 years in place of NAnt and MSBuild due to its programmability. Executing a concise script to do anything I want for my build process is a great bonus rather than writing complex XML configurations. At work, I hook this script into the team city build server (which supports running rake tasks). My tasks ranges from versioning, unit-tests, deploy to staging and manual click to deploy to production, without having server specific features. Anything the build server can do, I can do it from my machine.

To get started with rake in .NET, here are the steps that easily gets you up and running:

  1. Download ruby and install it. Ruby comes bundled with rake. Ensure they are installed in your Environment PATH. If somehow rake isn't bundled with ruby, its a gem anyway so install it with:
    gem install rake
  2. Install Albacore gem, a set of rake task made specifically for making building .NET projects easier. Tasks include running NUnit and MSTests, zip, nuget deployments, etc. Getting started found here. To install the gem:
    gem install albacore
  3. Download the visual studio plugin Rake Runner for visual studio 2012+. This allows you to run available rake tasks from the solution explorer.
  4. Create a visual studio project, place your Rakefile in the root folder of your project. This file should show up under Solution Items folder. This is where you write your scripts. Paste this code:
    require 'albacore'
    desc "Build"
    msbuild :build do |msb| :configuration => :Release
    msb.targets :Clean, :Build
    msb.solution = "YourSolution.sln"
    Replace the name of the solution with yours. Right click your solution, go to rake(Rake Runner extension) and select Build (refresh if not shown). The project should be built and the output shown in the output window pane.
  5. Go read this small tutorial which should help you get off the ground to writing some complex build scripts.
Build automation is a basic software engineering practise, rake is a great introduction for beginners to learn and very powerful and flexible for seasoned engineers. The support for rake in the .NET world is growing as more engineers see the power of rake.