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.
- Rubicant: http://github.com/mendicantx/rubicant
- Rake-dotnet: http://github.com/petemounce/rake-dotnet
- Rake-Me: http://github.com/agross/rake-me
- Raken: http://github.com/stevenharman/raken
- etc. etc. etc.
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 http://gems.github.com
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
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: Rake::MSBuildTask.new(:msbuild) do |msb|
10: msb.properties :configuration => :Debug
11: msb.targets [:Clean, :Build]
12: msb.solution = "lib/spec/support/TestSolution/TestSolution.sln"
15: desc "Run a sample assembly info generator"
16: Rake::AssemblyInfoTask.new(:assemblyinfo) do |asm|
17: asm.version = "0.1.2.3"
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"
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!
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.
Post Footer automatically generated by Add Post Footer Plugin for wordpress.