Dec 13, 2008 / .net ~ rake ~ ruby
Automate boring tasks with Rake in .NET

I've been using with Ruby Rake a few .NET projects (here's how) for a few weeks now. I'm enjoying it a lot. Here's why:

Mundane Task Automation - I can write Rake tasks to do all the mundane stuff I usually do by hand. Some examples tasks on a current project are

c:\Code\Proj> rake

The default Rake tasks builds my .NET solution (using MSBuild), finds and runs the Unit Test DLLs, runs an NDepend analysis on the code and outputs to a report folder, starts up the .NET ASP.NET development server and primes various caches.

Rake allows you to set a default task by clumping smaller tasks together

task :default => [:clean, :build, :test, :analyze, :start_server, :prime]

The code for a task is often blissfully simple, for example:

desc "Prime caches and stuff"
task :prime => :start_server do
  sh "curl --silent http://localhost:4705/Content/Search/aiport" #prime a lucene search
  #more calls to more pages here... 
end

Here's some other tasks I have

c:\Code\Proj> rake config_company_a
c:\Code\Proj> rake config_company_b

For a multi-tennanted application, I can quickly run these tasks to prepare the application for a given customer. It makes sure that the relevant config files are copied to the right place, and that the databases are loaded with the correct data etc.

Writing new rake tasks is EASY - New tasks can be written in no time. This is mainly because tasks are just simple code blocks written in Ruby, which can utilize all the Ruby libraries (Network, File IO, etc). No dicking about with studying API's or wading through XML files (and debugging them!)

Ruby is coming to .NET - As IronRuby matures, I suspect that Ruby scripts are going to become more common place in .NET solutions. Therefore, using Ruby in .NET solutions doesn't feel like I'm going against the grain so much!

Multiple Applications - Rake isn't just useful for .NET projects on Windows. You can stick a rakefile in any folder and have instantly have Rake at your disposal. You can reuse your Rake skills in any project on any platform. I'm currently using Rake for a writing project I'm doing. One useful Rake task I have scan the source code files and extract snippets out that are to be included in the document.

See also *Getting started with Rake *A sample Rake script


You may also like...