-
Notifications
You must be signed in to change notification settings - Fork 245
MSBuild Support
You can use standard Exec MSBuild task to run OpenCover from your MSBuild script, but it will require from you to craft command carefully taking into account that you need to escape parameters.
To simplify use of OpenCover from MSBuild there is a custom task to run OpenCover.
Custom task assembly could be found in MSBuild sub-folder in OpenCover distribution.
To add task to your MSBuild script, attach task assembly using UsingTask task
<UsingTask AssemblyFile="<PUT YOUR PATH TO ASSEMBLY HERE>\OpenCover.MSBuild.dll" TaskName="OpenCover.MSBuild.OpenCover" />or Import OpenCover.targets file from MSBuild folder and provide path to task assembly using OpenCoverMSBuildTasksPath property.
<PropertyGroup>
<OpenCoverMSBuildTasksPath>PUT YOUR PATH TO ASSEMBLY HERE</OpenCoverMSBuildTasksPath>
</PropertyGroup>
<Import Project="$(OpenCoverMSBuildTasksPath)\OpenCover.targets" />After that you can call OpenCover from your MSBuild script using OpenCover task.
Example:
<OpenCover
ReturnTargetCode="True"
ToolPath="$(ToolsFolder)\OpenCover\"
Filter="+[*]* -[*.Tests]* -[Autofac*]* -[Newtonsoft.Json]*"
ExcludeByAttribute="System.ObsoleteAttribute"
ToolExe="OpenCover.Console.exe"
Register="True"
ShowUnvisited="True"
Target="$(ToolsFolder)\nunit\nunit3-console.exe"
TargetWorkingDir="$(TestsBuildOutputFolder)"
TargetArgs="@(TestAssemblies->'"$(TestsBuildOutputFolder)\%(filename)%(extension)"', ' ') --result="$(TestResultsFolder)\unit-test-results.xml" --dispose-runners $(Traits)"
Output="$(CoverageResultsFolder)\coverage-results.xml" >
<Output TaskParameter="ExitCode" PropertyName="TestExitCode"/>
</OpenCover>Except base ToolTask properties specified here, there are a lot of OpenCover-specific parameters. All of them map to one of OpenCover.Console.exe parameters and for details you should read Usage document.
-
Target(string) - mappend totargetcommand-line parameter. -
ReturnTargetCode(bool) -Truewill addreturntargetcodecommand-line parameter. Default isFalse. -
TargetCodeOffset(int) - mapped toopencoverreturncodeoffsetcommand-line parameter. Not valid withoutReturnTargetCode=True. -
TargetArgs(string) - mapped totargetargscommand-line parameter. Don't forget to quote separate arguments with"if they could contain spaces. -
TargetWorkingDir(string) - mapped totargetdircommand-line parameter. -
Service(bool) -Truewill addservicecommand-line parameter. Default isFalse. -
ShowUnvisited(bool) -Truewill addshowunvisitedcommand-line parameter. Default isFalse. -
Register(bool) -Truewill addregister:usercommand-line parameter. Default isFalse. -
Output(string) - mapped tooutputcommand-line parameter. -
MergeByHash(bool) -Truewill addmergebyhashcommand-line parameter. -
Filter(list) - list of filters, mapped tofiltercommand-line parameter. -
ExcludeByFile(list) - list of files, mapped toexcludebyfilecommand-line parameter. -
ExcludeByAttribute(list) - list of filters, mapped toexcludebyattributecommand-line parameter. -
CoverByTest(list) - list of filters, mapped tocoverbytestcommand-line parameter. -
DefaultFilters(bool) -Falsewill addnodefaultfilterscommand-line parameter. Default isFalse.
You could've noticed that OpenCover task doesn't support some command-line parameters. If you need any of them, feel free to send pull request or create an issue.