Building .NET Systems with Ruby, Rake and Albacore Automated build tools have been around for a long time. Many of the early tools were simple batch scripts that made calls out to other command-line tools like compilers and linkers. As the need for more and more complexity in the build scripts was realized, specialized tools like Make were introduced. These tools offered more than just sequential processing of commands. They provided some logic and decision making as well as coordination of the various parts of the build process. Since Make was first introduced, many variations and specialized versions have been introduced for various languages and platforms. Rake - the “Ruby Make” system - may not have much more than its namesake to claim a connection to Make, but it is a build tool that is quickly growing in popularity and providing .NET developers with new options. .NET Build Tools From the early days and beta versions of .NET, the NAnt tool has been available and has been one of the most popular build systems in the .NET realm. MSBuild has been gaining in popularity since its first release, as well. It is now included as part of the .NET SDK and is used by Visual Studio and other build systems to automate some .NET project and solution builds. While NAnt and MSBuild are both configured through XML, other build tools have taken a code-based approach to build scripts. For example, PSake runs in Microsoft’s PowerShell, Bake uses the Boo language on the .NET platform and FAKE is bringing build automation through the F# language. Then there’s Rake… Rake natively runs in Ruby - just about every Ruby runtime that you can find, on any operating system that has a Ruby runtime, including the .NET platform through the IronRuby runtime. This helps to give Rake a very broad user base across a large number of platforms and languages. Even prior to the IronRuby runtime, though, Rake has been in use by .NET developers and has been growing in popularity. It is a powerful tool with many add-ons and options available including the Albacore project - a suite of Rake tasks that is targeted at building .NET systems. Listing 1 shows a complete build script for a simple Web project using Ruby, the Rake build system and the Albacore suite of Rake tasks. This script will generate common assembly information to be used in the project, build the project, run all unit tests for the project, and deploy the project’s runtime files out to a folder so that it can be pushed out to a Web server. In this article, I will show you how to get your .NET project building with Ruby, Rake and Albacore. I will also demonstrate some of the more advanced features of Albacore to help manage the configuration of your build process, generate project configuration files at build time, publish your project output, and more. The goal is to create a build script that is simple to set up, easy to read and easy to update. Before I show you the details of Albacore and its many options, you will need both Ruby and Rake installed on your Windows-based computer. If you already have them set up and are familiar with the basic Rake task usage, you can skip to the section titled “The Albacore Project”. If you would like to know more about the basics of Rake or you just want a quick refresher, continue reading the next sections. Installing Ruby If you already have Ruby running on your Microsoft Windows-based computer you should not need to reinstall it. If you don’t have Ruby, you can get the RubyInstaller package from http://rubyforge.org/projects/rubyinstaller/. Grab the latest installer for Ruby v1.8 (at the time of writing, “ruby-1.8.6-p383-rc1.exe”) and run it. When you get to the screen shown in Figure 1, be sure to check the option to modify your PATH variable. Whether you select the option to associate .rb and .rbw files with this Ruby installation is up to you. This option allows you to double-click your .rb and .rbw files to run them. I’ll run all of the examples shown in this article directly from a command prompt.  Figure 1: Be sure to select the “Add Ruby executable to your PATH” option.After you have completed the installation, open a command prompt and run “ruby --version”. You should see a response similar to that of Figure 2. This will verify that you have installed Ruby and that it has modified your PATH variable correctly.  Figure 2: Check to make sure Ruby installed correctly.If you receive an error saying that your system does not Ruby as a command or executable, you may need to manually update your PATH variable or restart your system. Once you have Ruby running, though, you can move on to installing Rake. | & | | 
By: Derick Bailey Derick Bailey is a software developer, architect, and technology leader in central Texas. He has more than 12 years of professional software development experience and more than 20 years of experience writing code. Derick is a blogger with LosTechies.com and has been active in developer communities around Texas (including Austin, San Antonio and Dallas) and online.
derickbailey@gmail.com What Is Albacore?
Albacore is a suite of Rake tasks that helps build .NET systems. It includes options for executing many common tools including MSBuild, NUnit, XUnit, creating AssemblyInfo files and more. |