# building .net projects with rake

I’ve been wearing my ruby slippers to work and I need to share the joy that is rake for .net projects. I’ve created/modified some rake tasks to ease automation and development of .net projects. Basically I wrap nunit and msbuild in rake and then use the wonder that is rake to create a clean and simple build script. Combine this with cruisecontrol.rb and you have a very nice automated build/testing system in place. Add watir/watin support to taste for that added punch.

You may be wondering why anyone would want to use rake when there are already multiple native build systems (nant and msbuild off the top of my head).

    <property name="myprj.basedir" value="c:\" />
<property name="filename" value="${path::combine(myprj.basedir,'version.txt')}" /> <if test="${not file::exists(filename) or file::get-length(filename) = 0}">
<echo message="The version file \${filename} doesn't exist or is empty!" />
</if>


Why would I want to use xml to write logical expressions? Seriously who wakes up in the morning and looks forward to that? I sure don’t. I’d rather use a full fledged programming language, if not for power than for clarity. Anything other than a real language, be it ruby, python or powershell is a pointless waste of time in my opinion. Why spend hours of your life fighting to express yourself within an xml-based cage. Check out this msbuild snippet:

    <ItemGroup>
<MDForm Include="TestForm1.cs">
<Author>
<Name>Ryan Flynn</Name>
<Email>rflynn@godelwasasmartnut.com</Email>
</Author>
</MDForm>
<MDFormOther Include="..\..\**\MySubProject\*.cs">
<Author>
<Name>Mark A. Guzman</Name>
<Email>mag@godelwasasmartnut.com</Email>
</Author>
</MDFormOther>
</ItemGroup>


That looks like a lot of junk to me.

    desc "compile cs files"
csc.files = FileList[ "**/MySubProject/*.cs" ]
end


Simple, concise and dare I say fun.

Now let’s take that last snippet a bit further, as msbuild will do all we want based on the solution (sln) file most of the time.

    desc "Run NUnit"
nunit.files = FileList['**/*Tests.dll'].exclude(/obj\//)
end

namespace :build do
desc "Compile Debug"
msbld.solutions = FileList['**/*.sln'].exclude(/obj\//)
msbld.config = "Debug"
end

desc "Compile Release"

I think you can guess what’s going on here. Now I can do rake build:release and have it run msbuild against the sln file. While that’s spiffy, it gets much nicer when you add in automated testing using nunit and watir combined with rspec. Plug this all into cc.rb or even cc.net and you get a very nice simple build system with automated testing. All of that with clean and concise syntax.