0

I am using below format for running OpenCover code coverage for MSTest from cmd:

C:\> \Your\OpenCover\Path\OpenCover.Console.exe -target:"\Your\Path\Here\MSTest.exe" -targetargs:"/testcontainer:\Your\DLL\Path\bin\Debug\TestProject.dll" -output:\Your\Output\File.xml -register:user

and below command to run Report Generator for generating report from OpenCover generated xml file:

C:\ReportGenerator\bin\ReportGenerator.exe -reports:"C:\Reports\MSTest\projectCoverageReport.xml" -targetdir:"C:\Reports\CodeCoverage"

And it is working fine, but the Paths for OpenCover.exe, MSTest.exe, ReportGenerartor.exe, etc. will always depends on machine, how can we make them relative, so that a generic batch file can be created to run these commands from any machine?

zmag
  • 7,825
  • 12
  • 32
  • 42

1 Answers1

0

You can use "forfiles" command to recursively search directories for the paths to those specific files. The below example will search as many drive letters as you enter:

for %%i in (c:\, d:\, e:\, ......) do if exist %%i (
    for /f "tokens=*" %%a in ('forfiles /p %%i /m OpenCover.Console.exe /s /c "cmd /c echo @path"') do set openCover=%%a
    for /f "tokens=*" %%b in ('forfiles /p %%i /m MSTest.exe /s /c "cmd /c echo @path"') do set msTest=%%b
)

From here, you can recall the variables as:

    %openCover% -target:%msTest% ...etc
TrahanL
  • 19
  • 3