OpenCover.Console.exe - Incorrect Arguments: The argument 'xxx.' is not recognised

1.8k Views Asked by At

I am implementing CodeCov for code coverage in c# with Visual Studio 2019 and I am using OpenCover and Xunit. My solution has two projects (Crossroads and CrossroadsUnitTests)

I have added the required nuget packages to the solution (OpenCover, xunit, xunit.runner.console, xunit.runner.visualstudio) and I want to run the OpenCover command locally to generate a coverage report but it seems I am having spaces in my path.

Below is the command I run in the Package Manager and the error i receive;

PM> OpenCover.Console.exe -register:user -target:"C:\Users\Mr. Erbynn\.nuget\packages\xunit.runner.console\2.4.1\tools\net46\xunit.console.exe" -targetargs:"C:\Users\Mr. Erbynn\source\repos\Crossroads\CrossroadsUnitTests\bin\Debug\netcoreapp3.1\CrossroadsUnitTests.dll -noshadow" -output:".\coverage.xml" -filter:"+[Crossroads*]* -[CrossroadsUnitTests*]*"

enter image description here

I have tried escaping with \" but it's not working.

Below are the command and error I receive in power shell when I run OpenCover in the root solution folder

 C:\Users\\"Mr. Erbynn\"\.nuget\packages\opencover\4.7.922\tools\OpenCover.Console.exe -register:user -target:"C:\Users\\"Mr. Erbynn\"\.nuget\packages\xunit.runner.console\2.4.1\tools\net46\xunit.console.exe" -targetargs:"C:\Users\\"Mr. Erbynn\"\source\repos\Crossroads\CrossroadsUnitTests\bin\Debug\netcoreapp3.1\CrossroadsUnitTests.dll -noshadow" -output:".\coverage.xml" -filter:"+[Crossroads*]* -[CrossroadsUnitTests*]*"

enter image description here

Below is the target test dll file hopefully; enter image description here

Please any help or suggestion will be very much appreciated.

1

There are 1 best solutions below

1
Cid On

From documentation

If your argument needs to escape quotes i.e. to pass arguments with spaces to that target process then you can use \" i.e. -targetargs:"\"c:\program files\" xyz"

So, your -targetargs should look like this :

//           vv---------------------------------------------------------------------------------------------------------------vv
-targetargs:"\"C:\Users\Mr. Erbynn\source\repos\Crossroads\CrossroadsUnitTests\bin\Debug\netcoreapp3.1\CrossroadsUnitTests.dll\" -noshadow"