Raking .NET projects in TeamCity
Faced with the unpleasant prospect of assembling yet another stack of xml files for an automated build, I thought I’d try rake instead. A couple of people here at 7digital have used Albacore before, so I started there.
1. Build
Use Albacore‘s msbuild task:
require 'albacore'
desc "Clean and build"
msbuild 'clean_and_build' do |msb|
msb.properties :configuration => :Release
msb.targets :Clean, :Build
msb.verbosity = "quiet"
msb.solution = "path/to/ProjectName.sln"
end
2. Run tests
This is also very straight forward with Albacore, but slightly more useful is applying the usual TeamCity test result formatting and reporting.
2.1 Tell your build where the NUnit test launcher is
TeamCity already has an NUnit runner, and the recommended way to reference it is with an environment variable.
Note: The runners are in the <TEAM CITY INSTALLATION DIR>/buildAgent/plugins/dotnetPlugin/bin directory.
2.2 Write the task
Once you have the path to the executable, you’re free to apply any of the available runner options.
Assuming you have added the TEAMCITY_NUNIT_LAUNCHER environment variable then the actual execution is then something like:
asm = 'ProjectName.Unit.Tests.dll'
nunit_launcher = ENV["TEAMCITY_NUNIT_LAUNCHER"]
sh("#{nunit_launcher} v2.0 x86 NUnit-2.5.0 #{asm}")
Beats hundreds of lines of xml I reckon.
References
- Albacore — rake tasks for.NET systems
- TeamCity NUnit launcher
- Setting environment variables for your TeamCity build
