Search code examples
msbuildcode-coverageopencover

OpenCover: Unable to run coverage for more than 2 assemblies


I am trying to use OpenCover With XUnit and MSBuild for our project and it works fine with one or two assemblies. But when the number of assemblies goes more than 2 it throws the below error:

    EXEC : error : unknown command line option: MyProj.UnitTest.dll
    [C:\CMR\Source\trunk\Build\Script\CMR.msbuild]
    Committing...
    No results, this could be for a number of reasons. The most common reasons are:
    1) missing PDBs for the assemblies that match the filter please review the output 
        file and refer to the Usage guide (Usage.rtf) about filters.
    2) the profiler may not be registered correctly, 
    please refer to the Usage guide and the -register switch.

Thought the problem would be with the 3rd assembly i added, so ran it individually again it worked fine. Below is the script I used:

<Exec Command='$(OpenCoverPath)\OpenCover.Console.exe "-target: $(XUnitPath)\xunit.console.exe" "-targetargs:C:\MyPath\UnitTest1.dll C:\MyPath\UnitTest2.dll C:\MyPath\UnitTest3.dll /noshadow" "-output:c:\OpenCoverReport\coverage.xml"'/>

And this is my assumption, for the purpose of posting here i had put paths of dll as C:\MyPath\UnitTest.dll but indeed the path is so huge and there are multiple assemblies with huge path. Does it has anything to do with this error?


Solution

  • try the -targetdir option of OpenCover

    e.g.

    <Exec Command='$(OpenCoverPath)\OpenCover.Console.exe -targetdir:"C:\MyPath" "-target: $(XUnitPath)\xunit.console.exe" "-targetargs:UnitTest1.dll UnitTest2.dll UnitTest3.dll /noshadow" "-output:c:\OpenCoverReport\coverage.xml" '/>