-
Notifications
You must be signed in to change notification settings - Fork 248
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 totarget
command-line parameter. -
ReturnTargetCode
(bool) -True
will addreturntargetcode
command-line parameter. Default isFalse
. -
TargetCodeOffset
(int) - mapped toopencoverreturncodeoffset
command-line parameter. Not valid withoutReturnTargetCode=True
. -
TargetArgs
(string) - mapped totargetargs
command-line parameter. Don't forget to quote separate arguments with"
if they could contain spaces. -
TargetWorkingDir
(string) - mapped totargetdir
command-line parameter. -
Service
(bool) -True
will addservice
command-line parameter. Default isFalse
. -
ShowUnvisited
(bool) -True
will addshowunvisited
command-line parameter. Default isFalse
. -
Register
(bool) -True
will addregister:user
command-line parameter. Default isFalse
. -
Output
(string) - mapped tooutput
command-line parameter. -
MergeByHash
(bool) -True
will addmergebyhash
command-line parameter. -
Filter
(list) - list of filters, mapped tofilter
command-line parameter. -
ExcludeByFile
(list) - list of files, mapped toexcludebyfile
command-line parameter. -
ExcludeByAttribute
(list) - list of filters, mapped toexcludebyattribute
command-line parameter. -
CoverByTest
(list) - list of filters, mapped tocoverbytest
command-line parameter. -
DefaultFilters
(bool) -False
will addnodefaultfilters
command-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.