NCover Documentation
Docs  ›  Legacy  ›  Reference  ›  MSBuild Tasks

Please visit Covering MSTest for updated information.

NCover provides MSBuild tasks for measuring and reporting on code coverage.

Including The Tasks

To use the NCover MSBuild tasks you will need to include them in your build file with the MSBuild UsingTask element:

<UsingTask 
  TaskName="NCover.MSBuildTasks.NCover"
  AssemblyFile="C:\Program Files\NCover\Build Task Plugins\NCover.MSBuildTasks.dll" />
<UsingTask
  TaskName="NCover.MSBuildTasks.NCoverReporting"
  AssemblyFile="C:\Program Files\NCover\Build Task Plugins\NCover.MSBuildTasks.dll" />

The <NCover> Task

Use the <NCover> task to measure code coverage within your MSBuild based build.

Basic Usage

<Target Name="Coverage">
  <NCover ToolPath="C:\Program Files\NCover\"
      TestRunnerExe="$(NUnitPath)\nunit-console.exe"
      TestRunnerArgs="TestAssembly1.dll TestRunner2.dll"
      CoverageFile="Coverage.xml"/>
</Target>

The above task runs NCover on the NUnit console test runner, giving it two test assemblies as arguments, and writes the resulting output to the file Coverage.xml.

Options

See the NCover.Console MSBuild Options for an exhaustive reference of the options available within the NCover MSBuild task.

The <NCoverReporting> Task

Use the <NCoverReporting< task to generate reports, merge coverage files, and fail builds based on coverage thresholds.

Basic Usage

<PropertyGroup>
  <CoverageReports>
    <Report>
      <ReportType>FullCoverageReport</ReportType>
      <Format>Html</Format>
      <OutputPath>CoverageReport\</OutputPath>
    </Report>
  </CoverageReports>
</PropertyGroup>
  
<Target Name="CoverageReport">
  <NCoverReporting ToolPath="C:\Program Files\NCover\"
      CoverageDataPaths="Coverage.xml"
      OutputReport="$(CoverageReports)"/>
</Target>

The example above sets up a property for the reports to generate and then uses the NCoverReporting task to load a coverage file and generate the report described in the property.

Options

See the NCover.Reporting MSBuild Options for an exhaustive reference of the options available with the NCoverReporting MSBuild task.

If you still need technical assistance, we can help:

Submit A Support Ticket