TDD developer

February 1, 2009

NAnt sucks and Rake rocks

Filed under: continuous integration — makka @ 1:34 pm
Tags: , , ,

In these days I’m moving my build scripts from NAnt to Rake. The main reason for doing this is that I’m moving from external dsl to an internal dsl. Internal DSLs are often the most approachable form of DSLs to write. Unlike external DSLs you don’t need to learn about grammars and language parsing, unlike language workbenches you don’t need any special tools. With internal DSLs you work in your regular language environment.

This means that now I build my build scritps just with ruby. I believe this is a good way to learn this nice language. Rake in fact is nothing more that a Ruby library.

Getting started with Rake and .NET is very easy:

  • Download the Ruby for windows one click installer.
  • Install it
  • Create a file Rakefile.rb (type is text file)
  • Type:
    task :default => :build
    
    task :build => [:compile, :test, :deploy] 
    
    task :compile do
      params = '/t:Rebuild /nologo /v:m /p:Configuration=Release src\demo.sln'
      msbuid = 'C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\MSBuild.exe'
      sh "#{msbuid} #{params}"
    end
    
    task :test do
     runner = 'tools\\Gallio\\Gallio.Echo.exe'
     assemblies = FileList["src/**/bin/Release/*.Fixture.exe"]
     extension = '' #'/e:TeamCityExtension,Gallio.TeamCityIntegration'
     sh "#{runner} #{assemblies} #{extension}"
    end
    
    task :deploy do
        sh "echo Task not yet implemented!"
    end
  • Open a command prompt (Start->Run->Cmd)

  • Type: cd c:\[my RakeFile.rb folder] (obviously put your own path in)

  • Type: rake
  • Done!

As you can see here above with rake there is no need to learn some crazy xml syntax. Whit this little script I compile my solution and run all unit tests. No need to write xml, only some ruby code.

Nothing more nothing less.

Technorati Tag: ,,,

8 Comments »

  1. This is truly awesome. Thanks for posting such helpful information. I use Gallio and TeamCity, so this was spot on!

    Comment by Ryan Montgomery — February 16, 2009 @ 2:52 pm | Reply

  2. Erm… With ant I just “cd …” and “ant” and I’m done… Other than replacing XML with Ruby, why would you recommend Rake over Ant?

    Obviously if you don’t like XML it’s a better choice, but we already have a good Ant setup, might it be worth it to learn Rake or would it just take us two weeks to migrate with nothing gained in the end?

    Comment by Anonymous — March 10, 2009 @ 5:26 pm | Reply

  3. Sorry but I never use Ant. I used only NAnt (the .net version)
    Honestly I migrate only some simple NAnt scripts. I left the most complex, but working, in xml.
    One thing is clear: I’ll make the new build scripts only using rake cause ruby is more simple & powerfull that xml

    Comment by makka — March 10, 2009 @ 7:30 pm | Reply

  4. Ant and NAnt are pretty much the same… So it sounds like Rake is nice to use, but doesn’t really provide anything Ant or NAnt don’t. Not that user-friendliness isn’t important…

    Comment by Anonymous — March 11, 2009 @ 2:56 pm | Reply

  5. Speaking about user-friendliness….
    Just try to do to compare a foreach loop made in xml+nant with a loop done using ruby.

    Comment by makka — March 11, 2009 @ 7:43 pm | Reply

  6. You might be interested in a project I’m working on; rake-dotnet? http://blog.neverrunwithscissors.com/tag/rake-dotnet and http://github.com/petemounce/rake-dotnet

    Comment by Peter Mounce — May 18, 2009 @ 4:35 pm | Reply

    • It looks very interesting! Nice idea

      Comment by makka — May 18, 2009 @ 8:37 pm | Reply

  7. Nice, I’ve been looking into this more and more. It looks good.

    Still not sure if it’s worth it for me (or my place of work). Our build scripts do a fair amount, but nothing hugely complex. No for loops etc… Typical config file setup, compilation, unit tests, robocopy deploy etc…

    Don’t think we’ll switch just yet. I know people don’t like xml, but at the moment the NAnt documentation is very clear and easy to follow (more so than learning ruby). But eventually we may swap as our build evolves.

    Comment by Rob — July 22, 2009 @ 9:15 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.