OpenCover MSBuild Integration - No results generat

2019-02-24 00:11发布

问题:

After getting OpenCover to work on my machine, the next step is getting it to work with the build server.

I've been trying to integrate OpenCover with MSBuild on a Bamboo Build Server. I have modified Build.proj as follows to run OpenCover after building the solution:

<Target Name="TestAndCodeCoverage" DependsOnTargets="Build" >
    <Message Text="Executing Unit Tests and running OpenCover to check code coverage..." />
    <MakeDir Directories="Coverage" />
    <Exec Command='"C:\Program Files (x86)\OpenCover\OpenCover.Console.exe" -target:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe" -targetargs:/testcontainer:"TestProject\bin\Release\TestProject.dll" -filter:+[*]* -output:Coverage\CodeCoverageResults.xml -register:user -mergebyhash' />
</Target>

The "Coverage" directory is created in the solution root directory (which is the working directory during the build). The tests are run and all pass, but after Committing.... is displayed in the Build log (what would be displayed in the command line), no results are generated and the Build moves on to the next task (creating a report with ReportGenerator - this fails as CodeCoverageResults.xml was not created).

When running the same command in the command line on the build machine everything works as expected, and a report can be generated by ReportGenerator.

Has anyone else had the same problem? Do I need to register equivalent dlls like in this PartCover example?

回答1:

As the build server is a service then I would use the -register switch only, however if on a build server I would always say you should register both the 32 and 64 bit profilers, once, using regsvr32 and then drop the -register switch i.e. There is no need to register and unregister the profiler each time.

The -register[:user] switch is for those scenarios where people (like myself) like to work under limited permissions.