Using TeamCity with PartCover 4

TeamCity 5 has support for .NET code coverage by using nunit with either NCover or PartCover. However, in order to get this working with the latest version of PartCover (4.0.10705) you’ll need to make a few tweaks to the PartCover installation.

Step 1 – Install or Upgrade TeamCity

Make sure you’re running the latest version of TeamCity (currently 5.1.3) as older versions do not have the code coverage support out of the box.

Step 2 – Install & Tweak PartCover

PartCover 4 can be downloaded from sourceforge. Run through the installer, which will install PartCover to C:Program Files (x86)PartCoverPartCover .NET 4.0 (on a x64 system):



TeamCity expects to find a file called PartCover.CorDriver.dll in the installation directory. However, with PartCover 4 this was renamed to PartCover.dll, so in order to get PartCover working with TeamCity, copy PartCover.dll and rename the copy to PartCover.CorDriver.dll


Step 4 – Fix the XSLT Templates

TeamCity seems to have problems rendering PartCover’s XSLT templates. I’ve put together a modified version that seems to work, and also allows you to click an assembly name to view the classes in that assembly. The template can be downloaded from here.

The fixed XSLT template should be placed in C:program files (x86)PartCoverPartCover .NET 4.0xslt

Step 5 – Configure your build

In this example, I’ll be running my unit tests through nant’s NUnit2 task, although this also works if you invoke TeamCity’s nunit-launcher directly as well as the teamcity-specific NUnitTeamCity task.

The “test” target in my nant script looks like this:

<target name="test">
    <formatter type="Plain" />
    <test assemblyname="PathToMyProject.Tests.dll" />

When configuring your TeamCity build, select “PartCover (2.2 or 2.3)” from the “.NET Coverage tool” section on the “Runner” page. Be sure to correctly set the path to the PartCover installation on the build server:



In this example, my build configuration is set to invoke the “ci” target of my build script which in turn calls the “test”target.

You’ll also need to select the assemblies to include/exclude. These are specified in the format of [assemblypattern]namespacepattern.

For example, to include all assemblies beginning with “MyApp”, but excluding the test assembly, the include/exclude patterns would look like this:


Note that I also specify the path to my custom XSLT template as :

C:Program FilesPartCoverPartCover .NET 4.0xsltCoverage.xslt=>index.html

This tells TeamCity to use the custom Coverage.xslt file when transforming PartCover’s outputs and to store the resulting HTML page as index.html.

Once this is done, you can run a build and look at the results. The summary page will contain a sumary of the coverage, as well as a link and a tab to view the full report:


The resulting code coverage file will look something like this: