Home > universidad > Setting up MSBuild with NUnit, NCover and NCoverExpxlorer

Setting up MSBuild with NUnit, NCover and NCoverExpxlorer

1. Introduction

The following guide will help you to create and execute an MSBuild configuration that will run tests with NUnit and also provide a NCover coverage report. The most challenging part was working with the free community edition for the tools, .NET 4.0, and also setting up the environment on a Windows 7 64 bit laptop.

2. Getting the right tools and know them

We need to download the right tools at the right version, I will provide a brief description of each

NUnit (

This tool will help us to run our unit tests. You can download it from here: http://nunit.org/index.php?p=download. If you go to the bin folder, you will see two versions of the nunit-console application, we will be using nunit-console-x86.exe

NCover (1.5.8)

It will generate a coverage.xml file, that indicates how much code has been tested on our project. It has a community free option, which is the last option at the following link: http://www.ncover.com/download/current. You need to register in order to download it.

NCoverExplorer (

Helps us to create an HTML report file from the coverage.xml generated with NCover. The free version is available at: http://www.kiwidude.com/dotnet/DownloadPage.html

You will need to extract the files at a specific location.

NCoverExplorer Extras (

This package contains a couple of plugins that can help us with tasks in MSBuild, which can be downloaded also from: http://www.kiwidude.com/dotnet/DownloadPage.html

  • NCoverExplorer.MSBuildTasks.dll
  • NCoverExplorer.NAntTasks.dll

We’ll see how do we link these in the MSBuild file. I recommend you to put the extras folder in the same directory you installed NCoverExplorer

TestDriven.Net (3.3.2779)

As an alternative, you can download and install TestDriven.Net, which contains the three applications described above, you can get it here: http://www.testdriven.net/download.aspx

Note that, still you will need to get the NCoverExtras for the MSBuild task plugins

I recommend using TestDriven, since it also installs you a nice add-on for Visual Studio, which helps you to run tests easily. I will use TestDriven for the rest of the tutorial

3. Doing it

I suggest to go to https://github.com/aharita/calculator while reading the rest, so you can examine the complete source code. In this section I will explain some of the troubles I got into, and how to solve them. Some of those are particular to .NET 4.0 and having Windows 7 64 bit

MSBuild example file

We need to add three tasks in our MSBuild file

		AssemblyFile="C:\Program Files (x86)\TestDriven.NET 3\NCoverExplorer\NCoverExplorer.Extras\bin\NCoverExplorer.MSBuildTasks.dll"/>
		AssemblyFile="C:\Program Files (x86)\TestDriven.NET 3\NCoverExplorer\NCoverExplorer.Extras\bin\NCoverExplorer.MSBuildTasks.dll"/>
		AssemblyFile="C:\Program Files (x86)\TestDriven.NET 3\NCoverExplorer\NCoverExplorer.Extras\bin\NCoverExplorer.MSBuildTasks.dll"/>

We also need to add the proper sections for handling NUnit, NCover and NCoverExplorer

	<Target Name="NUnitSimple">
			Command="&quot;C:\Program Files (x86)\TestDriven.NET 3\NUnit\2.6\nunit-console-x86.exe&quot; &quot;C:\Users\aharita\Documents\GitHub\calculator\Calculator.Tests\bin\Debug\Calculator.Tests.dll&quot;"/>

	<Target Name="NCoverSimple">
			ToolPath="C:\Program Files (x86)\TestDriven.NET 3\NCover\1.5.8\"
			CommandLineExe="C:\Program Files (x86)\TestDriven.NET 3\NUnit\2.6\nunit-console-x86.exe"

	<Target Name="NCoverExplorerSimple" DependsOnTargets="NCoverSimple">
			ToolPath="C:\Program Files (x86)\TestDriven.NET 3\NCoverExplorer"
			ProjectName="Calculator Operations Tests"

Build.bat helper file

I also have a build.bat file that helps you to run msbuild with the build.xml MSBuild configuration

set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe build.xml

4. Troubleshooting

There are some problems that you might have while trying to do the setup, the most common ones are:

Profiler connection not established.

The full error is:

Profiled process terminated. Profiler connection not established.
error MSB6006: "NCover.Console.exe" exited with code 1.

Solution is:

  • You need to use nunit-console-x86.exe on all the MSBuild references
  • You need to execute the following in the same command window you execute your msbuild script
    • set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler

You can see the example file provided on GitHub

Empty coverage.xml file

Sometimes, you will end up with an empty coverage.xml file, some solution to this:

  • Open nunit-console-x86.exe.config and change it as follows:
<startup useLegacyV2RuntimeActivationPolicy="true">
 <!-- Comment out the next line to force use of .NET 4.0 -->
 <supportedRuntime version="v4.0.30319" />
 <supportedRuntime version="v2.0.50727" />

4. Resources

Hopefully, this guide will be helpful and you won’t have the same headaches as I had trying to do the setup. Following are some links resources that helped me through the problem.





  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: