Question

In the post-build event of my unit test project I run OpenCover and ReportGenerator to get a code coverage report:

del "$(SolutionDir)TestResults\Coverage\*.*"

"$(SolutionDir)packages\OpenCover.4.5.1923\OpenCover.Console.exe" 
-register:user 
-target:"$(MSBuildProgramFiles32)\Microsoft Visual Studio 12.0\
   Common7\IDE\MSTest.exe" 
-targetdir:"$(ProjectDir)bin\$(ConfigurationName)" 
-targetargs:"/testcontainer:\"$(TargetPath)\"" 
-output:"$(SolutionDir)TestResults\Coverage\coverage.xml" 
-filter:"+[MyProject]* "

$(SolutionDir)packages\ReportGenerator.1.9.1.0\ReportGenerator.exe" 
-reports:"$(SolutionDir)TestResults\Coverage\coverage.xml" 
-targetdir:"$(SolutionDir)TestResults\Coverage"

call "$(SolutionDir)TestResults\Coverage\index.htm"

The final step is to open the generated HTML report. With the current call command it opens the HTML report in my default web browser. But I would like it if the report could get opened within Visual Studio itself.

If and how would I achieve this?

Was it helpful?

Solution

I have actually got it to work using PowerShell and the Navigate method in the VS core automation wrapper, EnvDTE. I replaced the last call command with the following:

powershell 
-ExecutionPolicy Unrestricted 
-Command "& { $dte = [System.Runtime.InteropServices.Marshal]::
                     GetActiveObject(\"VisualStudio.DTE.11.0\"); 
              $dte.ItemOperations.Navigate(
                     \"$(SolutionDir)TestResults\Coverage\index.htm\"); }"

And that opens the report in a new browser tab inside the VS project.

OTHER TIPS

Very simple thing worked for me in post build event-

start http://localhost/MYWeb/Home.aspx

You might be able to use devenv to open the file using the command line switches.

devenv /edit $(SolutionDir)TestResults\Coverage\index.htm

but it may open it up as a file to edit rather than to view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top