NCover Documentation
Docs  ›  Legacy  ›  Reference  ›  NCover 2.0  ›  Build Tasks

This page explains how to create NAnt and MSBuild tasks to run NCover from your build script using the dlls provided with your copy of NCover.

<a name="nant"></a>
  <h2>NAnt Task Integration</h2>
  <p>
  To make the NAnt tasks available in your project file, include this line at the top of the script:
  </p>
    <code class="inline"><pre>&lt;loadtasks assembly="NCoverExplorer.NAntTasks.dll"/&gt;
    </pre></code>

  <a name="nant_ncover"></a>    
  <h3>NCover Task</h3>
  <p>
  Then, as part of your automated testing, you can profile the new build as the unit tests run.
  </p>
      <code class="inline"><pre>

<target name="RunUnitTests"> <ncover program="C:\Program Files\NCover\NCover.Console.exe" {path.nunit.exe}" {NAntProjectDirectory}" commandLineArgs="unittests.dll" coverageFile="releasetestresults.xml" /> </target>

However, the easiest way to create NAnt tasks for NCover is to set up the runtime options you want in NCoverExplorer's Run dialog, and then copy the msbuild task output that NCoverExplorer generates automatically.

NCoverExplorer Task

You can also use NCoverExplorer to run NCover, generate an HTML report, and then open that report in a browser window.

<target name="CreateReport">
  <ncoverexplorer
    projectName="MyProject"
    reportType="ModuleClassSummary" 
    outputDir="C:\Reports\"
    xmlReportName="MyProject.xml"
    htmlReportName="MyProject.html"
    showExcluded="True"
    satisfactoryCoverage="95" >
    <fileset>
      <include name="Coverage.xml" />
    </fileset>
    <exclusions>
      <exclusion type="Assembly" pattern=".Tests" />
      <exclusion type="Namespace" pattern=".Tests" />
    </exclusions>
  </ncoverexplorer>
</target>
<target name="OpenReport">
  <exec program="C:\Program Files\Internet Explorer\iexplore.exe" />
    <arg value="C:\Reports\MyProject.html">
  </exec>
</target>
      

NUnit Task

You can also generate an nunit project file from within the NAnt project to simplify the nunit command line.

<target name="RunTests">
  <nunitproject
    project="C:\dev\myprogram\release\MyApp.nunit" 
    appConfig="C:\dev\myprogram\release\App.config">
    <fileset basedir="C:\dev\myprogram\release\">
      <include name="Test.dll" />
      <include name="UnitTest.dll" />
    </fileset>
  </nunitproject>
  <ncover
    commandlineExe="nunit-console.exe"
    commandlineArgs="C:\dev\myprogram\release\MyApp.nunit"
    coverageFile="releasetestresults.xml"
  />
</target>
      

NDoc2 Alpha Task

Finally, it is also possible to automatically run NDoc2 Alpha to generate documentation for your project. The easiest way to create the content for the task is to use the NDocGui and save the resulting configuration file, then just paste in the <documenter> and any other sections you want into your NAnt script.

<ndoc2 program="C:\util\ndocalpha\bin\ndoc2.exe">
  <assemblies>
    <include name="program.exe" />
    <include name="program.core.dll" />
    <include name="program.interfaces.dll" />
  </assemblies>
  <documenters>
    <documenter name="MSDN-CHM">
      <property name="IncludeFavorites" value="False" />
      <property name="OutputDirectory" value="doc\MSDN" />
      <property name="HtmlHelpName" value="MyApp" />
      <property name="Title" value="MyApp Class Library" />
      <property name="Version" value="" />
      <property name="UseAssemblyShadowCache" value="False" />
      <property name="DocumentExplicitInterfaceImplementations" value="True" />
      <property name="AssemblyVersionInfo" value="AssemblyFileVersion" />
      <property name="CopyrightText" value="2007 My Company Ltd" />
    </documenter>
  </documenters>
</ndoc2>
      

MSBuild Task Integration

To make the MSBuild tasks available in your project file, include these lines at the top of the script:

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

NCover Task

Then, as part of your automated testing, you can profile the new build as the unit tests run.

<Target Name="RunUnitTests">
  <NCover
    ToolPath="C:\Program Files\NCover\"
    WorkingDirectory="$(MSBuildProjectDirectory)"
    CommandLineExe="nunit-console.exe"
    CommandLineArgs="unittests.dll"
    CoverageFile="releasetestresults.xml"
  />
</Target>
          

However, the easiest way to create msbuild tasks for NCover is to set up the runtime options you want in NCoverExplorer's Run dialog, and then copy the msbuild task output that NCoverExplorer generates automatically.

NCoverExplorer Task

You can also use NCoverExplorer to run NCover, generate an HTML report, and then open that report in a browser window.

<Target Name="CreateReport">
  <NCoverExplorer
    ProjectName="MyProject"
    ReportType="ModuleClassSummary" 
    OutputDir="C:\Reports\"
    XmlReportName="MyProject.xml"
    HtmlReportName="MyProject.html"
    ShowExcluded="True"
    SatisfactoryCoverage="95"
    CoverageFiles="Coverage.xml" 
    Exclusions="Assembly=.Tests;Namespace=.Tests"
  />
</Target>
<Target Name="OpenReport">
  <Exec Command="C:\Program Files\Internet Explorer\iexplore.exe C:\Reports\MyProject.html" />
</Target>
      

NUnit Task

Finally, you can also generate an nunit project file from within the msbuild project to simplify the nunit command line.

<ItemGroup>
  <ProjAsemblies Include="C:\dev\myprogram\release\Test.dll" />
  <ProjAsemblies Include="C:\dev\myprogram\release\UnitTest.dll" />
</ItemGroup>
<Target Name="RunTests">
  <NUnitProject
    Project="C:\dev\myprogram\release\MyApp.nunit" 
    AppConfig="C:\dev\myprogram\release\App.config"
    Assemblies="@(ProjAsemblies)
  />
  <NCover
    CommandLineExe="nunit-console.exe"
    CommandLineArgs="C:\dev\myprogram\release\MyApp.nunit"
    CoverageFile="releasetestresults.xml"
  />
</Target>
      

If you still need technical assistance, we can help:

Submit A Support Ticket