If you need to register and unregister NCover as part of your build process you can easily use the provided NCover.Registration.exe provided by the NCover installation.
Here's a snippet of a build file:
<BuildRoot>$(MSBuildThisFileDirectory)</BuildRoot>
<BuildToolsDir>$(BuildRoot)\BuildTools</BuildToolsDir>
<BuildSolutionDir>$(BuildRoot)\Src</BuildSolutionDir>
<NCoverRootDir>$(BuildToolsdir)\NCover</NCoverRootDir>
<NCoverConsoleExe>$(NCoverRootDir)\NCover.Console.exe</NCoverConsoleExe>
<NCoverRegistrationExe>$(NCoverRootDir)\NCover.Registration.exe</NCoverRegistrationExe>
<NCoverMSBuildTaskAssembly>$(NCoverRootDir)\BuildTaskPlugins\NCover.MSBuildTasks.dll</NCoverMSBuildTaskAssembly>
<TestMSTestExe>$(VS100COMNTOOLS)\..\IDE\MSTest.exe</TestMSTestExe
<TestResultsDir>$(BuildRoot)TestResults</TestResultsDir>
<UsingTask TaskName="NCover.MSBuildTasks.NCover" AssemblyFile="$(NCoverMSBuildTaskAssembly)"/>
<Target Name="TestNCoverRegister">
<Exec Command=""$(NCoverRegistrationExe)" //license [KEY]"/>
</Target>
<Target Name="TestNCoverUnRegister">
<Exec Command=""$(NCoverRegistrationExe)" //deactivate"/>
</Target>
<Target Name="TestUnitsNCover" DependsOnTargets="Prepare">
<MsBuild Projects="$(MSBuildProjectFile)" Targets="TestNCoverRegister" Properties="ForceExecute=1"/>
<Delete Files="$(TestResultsDir)\UnitTests.trx" />
<NCover
BuildId="$(BuildNumber)"
ToolPath="$(NCoverRootDir)"
TestRunnerExe="$(TestMSTestExe)"
TestRunnerArgs="/testcontainer:"$(BuildDir)\MYAPP.UnitTests.dll" /resultsfile:"$(TestResultsDir)\UnitTests.trx" /runconfig:"$(BuildSolutionDir)\LocalTestRun.testrunconfig""
CoverageFile="$(TestResultsDir)\UnitTestCoverage.nccov"
/>
<MsBuild Projects="$(MSBuildProjectFile)" Targets="TestNCoverUnRegister" Properties="ForceExecute=1"/>
</Target>
Some notes about this build:
- NCover is not installed in the Program Files directory, I like to keep all files required for a solution as part of the source so all of my "tools" are kept in \BuildTools. This way if a new developer checks out the solution root they don't need to install any additional software (apart from the core things like VS and SQL Server etc)
- You'll notice I'm not using Call task or DependsOnTargets to run the register/unregister targets, I'm using the MsBuild target to call the same build file in order to execute the same MSbuild target twice. The reason I do this is because I have another integration test target that dopes the same thing as the unit tests but on a different DLL, so I want to be able to call the targets individually or together as part of a commit build
6bda04b1-66d6-491e-9478-06269e5b5b4b|0|.0