Albacore: A Suite Of Rake Build Tasks For .NET Solutions

Albacore Tuna - After my previous post on building a “real” rake task, I decided to dive in head first and learn how to get this stuff done. I chose to drive the tasks out via rspec, through a TDD process, and I created a couple of rake tasks that are proving to be quite useful to me: an msbuild task and an assembly info generate task. Yeah, I know that this has been done to death, at this point. During the trials and tribulations of me getting down and dirty with ruby, rake, gemspec, rspec, etc, I came across some libraries that already do exactly what I set out to do.

The point is, I know I am re-inventing the wheel. So, why did I decide to continue with my efforts, and actually produce Albacore? First and foremost, I did it so that I would have an excuse and good reason to really dive down deep into what it takes to produce a high quality, valuable toolset using ruby, rake, rspec, etc. I wanted to learn, and wanted to find out what I could and could not do easily with these tools.

With the idea of using Albacore as a way for me to learn all of these tools, I don’t plan on giving up on this toolset and using another one. I have enjoyed the process of learning and creating something useful in a new framework, and I can see a lot of value in what I’ve already created. The end result has multiple benefits and was well worth the effort.

So, with all that in mind, I present to you: Albacore – A Suite of Rake Build Tasks for .NET Solutions.

What Is Albacore?

The sub-title and everything I’ve stated so far, really do give this away. I wanted to have a suite of rake tasks that I can use for my .net solutions. In the process of creating this suite, though, I wanted to avoid the mistake of duplicating a lot of code between the rake tasks and the underlying object model that gets executed by the tasks. I’ve taken the time to learn how the rake tasks work and how to properly create an ultra-simple, light-weight task wrapper around an object model that does the real work.

At the time of this writing, there are two primary tasks Albacore includes: MSBuiltTask and AssemblyInfoTask.

MSBuildTask: This task is used to build your .NET solutions. Internally, this task calls out to the MSBuild command line. This will allow you to run the task against a .NET solution directly, or against an MSBuild file or anything else that the MSBuild exe allows you to build.

AssemblyInfoTask: This task is used to generate your assembly information – version, copyright, title, description, etc. The assembly info task writes the attributes that you supply out to the file that you specify. At this time, the only language that this task supports is C#. I don’t have any use for a VB or other .NET language version of this task, so I have not provided any mechanisms to write into other languages. If there is sufficient interest in other languages, though, I’ll work with those who are interested to create a language option.


How Do I Get Albacore?

If you would like to use Albacore for your rake tasks, all you need to do is install the gem via github’s gem server. To do this, follow these instructions:

1. Setup github as a gem source. Open a command prompt for ruby, and run this command:

gem source –a

This will add github as a source repository for you to install ruby gems from. The good news is, you only have to do this one. After you add this source, you will be able to pull any gem you want from github, whenever you want.

2. Install the Albacore Gem. Open a command prompt if you don’t have one open already, and run this command:

gem install derickbailey-Albacore

Be careful to get the spelling of my name correct (one “r”) and the capitalization of Albacore correct. This will install the library on your local box and you will be ready to use it.


How Do I Use Albacore?

To use Albacore on your project, be sure you have it installed first. Then you only need to

require ‘albacore’

in your rakefile, and you can get started. Here is the example that I have included in the default rakefile in the albacore gem:

   1: require 'albacore'


   3: namespace :albacore do


   5:     desc "Run a complete Albacore build sample"

   6:     task :sample => ['albacore:assemblyinfo', 'albacore:msbuild']


   8:     desc "Run a sample build using the MSBuildTask"

   9: do |msb|

  10: :configuration => :Debug

  11:         msb.targets [:Clean, :Build]

  12:         msb.solution = "lib/spec/support/TestSolution/TestSolution.sln"

  13:     end


  15:     desc "Run a sample assembly info generator"

  16: do |asm|

  17:         asm.version = ""

  18:         asm.company_name = "a test company"

  19:         asm.product_name = "a product name goes here"

  20:         asm.title = "my assembly title"

  21:         asm.description = "this is the assembly description"

  22:         asm.copyright = "copyright some year, by some legal entity"

  23:         asm.custom_attributes :SomeAttribute => "some value goes here", :AnotherAttribute => "with some data"


  25:         asm.output_file = "lib/spec/support/AssemblyInfo/AssemblyInfo.cs"

  26:     end

  27: end

I’ve included this example build of the Albacore tasks in the rakefile at the root of the gem installation, as well as all of the rspec tests for the library. With this, you can run the tests or the sample builds directly from the rakefile, in the installation folder of the gem.

You can run this sample with the following command(s):

“rake albacore:sample” – runs all of the tasks from Albacore

“rake albacore:msbuild” – only runs the msbuild task

“rake albacore:assemblyinfo” – only runs the assembly info generator task

I’m also planning to maintain the Albacore wiki on the github page, with instructions on how to install it, how to use the individual tasks, etc. You can get the link to the github project in the next section of this post.


Can I Get The Albacore Source Code?

Yes! I’m doing this as an open source (MIT license) project on my github account. You can grab the source code, fork it to your github account, or do whatever else the magic of git + github lets you do. If you add something useful, fix a bug, or make something more ‘ruby-like’ or more clear and understandable, just let me know and I’ll see about merging your changes into the main project!


What’s Next?

I am planning to continue extending Albacore, as the needs of my projects continue to evolve. Right now, these two basic tasks are enough to get me off the ground and running. The future will likely bring NCover, NUnit, and other tasks into the mix, as my teams have a need for them.


(albacore tuna photo by daviddesign. used here under a creative commons license)

About Derick Bailey

Derick Bailey is an entrepreneur, problem solver (and creator? :P ), software developer, screecaster, writer, blogger, speaker and technology leader in central Texas (north of Austin). He runs - the amazingly awesome podcast audio hosting service that everyone should be using, and where he throws down the JavaScript gauntlets to get you up to speed. He has been a professional software developer since the late 90's, and has been writing code since the late 80's. Find me on twitter: @derickbailey, @mutedsolutions, @backbonejsclass Find me on the web: SignalLeaf, WatchMeCode, Kendo UI blog, MarionetteJS, My Github profile, On Google+.
This entry was posted in .NET, Albacore, C#, Continuous Integration, Git, Rake, Ruby. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Derick,

    It’s likely a bit more “rakish” to structure the gem so that “lib” is not necessary when requiring Albacore. It’s usually more idiomatic to do something simpler like: require ‘albacore’

  • @Scott,

    ya – i got that feeling from examining my use of other rake tasks… had a hard time figuring out how to make that work… I’ll definitely look into it more, though.

  • @Scott,

    well it turns out it already works without specifying ‘lib’… i just installed the gem, and ran a test rake file that only specified: require ‘albacore’… worked fine! I’ve updated this post to correct the require statement.

  • Careful. The more you use Ruby the less you will love C#. It’s having to go back to driving a dump-truck after riding your motorcycle.

    I am a troll.

  • @Brian,

    too late, man. I spent some time with Ruby on Rails during a couple days training w/ Scott Bellware… a day later, I looked at some mvc code and about puked. :)

  • chris mitchell

    Great post Derick, thanks.

  • Derick,

    I also found myself in need for a couple of Rake tasks when we migrated our far-too-complex NAnt scripts to Rake. I didn’t go down the TaskLib route like you did because I basically never saw a need to have (and use) a TaskLib when classes would achieve the same result. But maybe I am just missing the point about TaskLibs. Great to see some tests in Albacore as that’s something that I wasn’t able to look into.

    Anyway, you might want to have a look at “rake-me” which contains a host of Rake tasks that you might require in the future.


  • @Alexander,

    Thanks for the link to Rake-Me. I was looking for that when I wrote this post, but couldn’t find it. I’m updating the post to include that in the list at the top.

    The reason I decided to go down the route of creating the rake tasklibs, was to be a bit more “professional” in my approach to the problem. The truth is, the task lib is just a simple adapter pattern – it takes the real object model that sits behind the scenes and exposes it to rake directly through a custom rake task. If you take a look at the MSBuildTask or the AssemblyInfoTask in Albacore, you won’t see very much code, because all the real work is done in the object model.

  • Aaron Boxer

    Great post. I found this typo: “gem source” should read “gem sources”