Build, test, refactor - a simple .NET Rake script
I just blogged about setting up Rake with .NET. Based on a few resources online (and some Ruby experience), I've cobbled together a quick Rakefile.rb that can build, test and analyze a solution.
- Build calls MSBuild on the Visual Studio solution file.
- Test calls NUnit on all DLLs with Test in the name
- Analysis calls NDepend which will then give me a list of top 10 refactorings.
What's nice is being able to just type rake and all these steps are performed. I know you can do this with Nant, but you have to admit the Rakefile.rb is very concise! If I want to run tasks individually, I can also type:
rake compile
rake test
rake analyze
Here's the Rakefile.rb script:
#Rakefile.rb
require 'rake'
require 'build_helper'
task :default => [:compile, :test, :analyze]
desc "MSBuild solution"
task :compile do
msbuild :squilbo
end
desc "NUnit tests"
task :test do
files = FileList['**/*.Test.*.dll'].exclude(/obj\//)
files.each do |file|
sh "#{NUNIT} #{file}"
end
end
desc "NDepend analysis"
task :analyze do
sh "#{NDEPEND} \"#{current_directory}\NDepend.Core.Xml\""
end
This file also includes another file - build_helper.rb, which contains constants and useful functions.
This could have been included inline, but I thought it might be neater to keep it separate.
#build_helper.rb
def msbuild(solution)
sh "#{MSBUILD} #{solution}.sln"
end
def current_directory
Dir.pwd.gsub(/\//,'\')
end
#
# Put your own definitions here. You could also load from a YAML or XML file
#
NUNIT = 'C:\Program Files\NUnit 2.4.7\bin\nunit-console-x86.exe'
NDEPEND = 'C:\Program Files\NDepend\NDepend.Console.exe'
MSBUILD = 'C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe'
SOLUTION_FOLDER = current_directory
This is all just the first 30 minutes of playing with Rake, so I'm sure there are many better ways of doing things. But, thought I'd share the first experiences.
I'm looking forward to playing with NDepend more (they were kind enough to give me a license), my main goal is to get it tightly integrated into my development process so I can actually get some real, ongoing benefit from it.
Comments
-
Hi,
just ran across this blog the other day, and saw a couple of interesting posts on the main page. Is there way to look at the archive of blog posts by date, or a way to view more than 1 page of your most recent posts?
The .net tag (http://www.tobinharris.com/tags/.net) loads (in FF3 at least) as html source rather than interpreting the html and presenting this.
The C# tag (http://www.tobinharris.com/tags/C#) goes to a page that indicates posts tagged with “C” rather than C#
Several of your tags look like they’ve been non properly split (e.g. “nhibernate faq software” and “nhiberntae,ajax,software”
I have also emailed this comment to your socena email.
Regards,
Joshka
-
Great stuff! Subscribed to your blog.
By the way We’re looking for beta testers, you might help us spread the word through your blog!