2

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?

Vinoth
  • 2,419
  • 2
  • 19
  • 34

1 Answers1

1

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" '/>
Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56
  • I cannot do it that way. coz all my test assemblies are not in the same directory. – Vinoth Aug 28 '15 at 04:15
  • Does it mean i have to have all the test assemblies in the same directory if i had to run for multiple assemblies? – Vinoth Aug 28 '15 at 04:17
  • This way - yes - or you can run each assembly separately and merge the results using `-mergeoutput` - I suggest you read the [usage](https://github.com/OpenCover/opencover/wiki/Usage) guide – Shaun Wilde Aug 28 '15 at 22:50
  • The problem with running each assembly separately is, i have to keep updating the build scripts as and when i introduce new test projects. I had a look at the usage guide, it helps with the syntax but not when it comes to running multiple assemblies thru a single exec – Vinoth Aug 31 '15 at 13:13
  • 1
    Since you are using MSBuild you can auto build a collection of files (an ItemGroup) and then use that collection to run OpenCover for each assembly. – Shaun Wilde Aug 31 '15 at 20:44
  • that solved most of my issues.. thanks for the awesome free tool!! – Vinoth Sep 01 '15 at 10:49