Thursday, April 5, 2007

MSBuild, NUnit and CruiseControl.Net

I thought this would be the de facto standard setup for most .Net project these days. But it turns out making the whole thing work is far from "standard". Here are the steps I took, for what it's worth:

  • MSBuild is installed with .Net Framework 2.0. Install CruiseControl from here, and NUnit from here.
  • Install MSBuild Community Tasks, which includes a NUnit task for MSBuild.
  • Now you can create NUnit task in MSBuild project like this:
  •    <Import  Project="$(MSBuildExtensionsPath\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
       <NUnit Assemblies="myTest.dll"
           ToolPath="C:/Program Files/NUnit 2.4/bin/" 
           OutputXmlFile="TestResult.XML"/>
  • Setup MSBuild task in CruiseControl. Strangely, the custom logger used in the example is NOT part of CruiseControl installation. You need to download it here and put it into CruiseControl installation folder.
  • Use NUnit with CruiseControl. Since NUnit is setup as part of MSBuild, the only thing left to do is to merge the test result output into build log.
  • Finally, if CruiseControl is setup as a windows service and you're compiling a C/C++ project with MSBuild, you might get this error:
  •       Fatal Error C1902: Program database manager mismatch; please check your installation.
    Believe me, this has nothing to do with the pdb files. Unfortunately, link to the hotfix mentioned in the KB article is broken. An alternative is to set your CruiseControl service to run under a different use account than the default SYSTEM. (Yeah, I know...)