asp.net-corecode-coverageiis-expressopencover

OpenCover for ASP.Net Core application running on IIS Express


I'm trying to get Code Coverage for a Asp.Net Core application(DebugType - Full) running on IIS Express using OpenCover.

As specified here I tried setting the environment variable and then run the OpenConsole. Only difference being that I'm trying to open using iisexpress.exe instead of VSIISExeLauncher.exe

set LAUNCHER_ARGS=-p "C:\Program Files\dotnet\dotnet.exe" -a "exec \"C:\CoreWebApp\CoreWebApp\bin\Debug\netcoreapp2.0\CoreWebApp.dll\"" -pidFile $([System.IO.Path]::GetTempFileName()) -wd "C:\CoreWebApp\CoreWebApp"
set LAUNCHER_PATH=C:\Program Files\IIS Express\iisexpress.exe

OpenCover.Console.exe -target:"C:\Program Files\IIS Express\iisexpress.exe" -targetargs:"/config:""C:\CoreWebApp\.vs\config\applicationhost.config"" /site:CoreWebApp" -output:"Coverage.results.xml" -register:user –targetdir:"C:\CoreWebApp\CoreWebApp\bin\Debug\netcoreapp2.0"

I get 'HTTP Error 502.5 - Process Failure' when I hit any URL in the application.

Alternatively, if I try to run the application directly as below. When I press CTRL+C to stop the server, the OpenCover also stops.

OpenCover.Console.exe -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:"C:\CoreWebApp\CoreWebApp\bin\Debug\netcoreapp2.0\CoreWebApp.dll" -output:"Coverage.results.xml" -register:user -oldStyle

Any idea how to use OpenCover with a Asp.Net Core application?


Solution

  • The below worked.

    Set the environment variables.

    set LAUNCHER_ARGS=-p "C:\Program Files\dotnet\dotnet.exe" -a "exec ""C:\Users\baga\source\repos\CoreWebApp\CoreWebApp\bin\Debug\netcoreapp2.0\CoreWebApp.dll"""
    set LAUNCHER_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\Web Tools\ProjectSystem\VSIISExeLauncher.exe
    

    Below command can be used if you want to just run the dot net core application in IIS express.

    "C:\Program Files\IIS Express\iisexpress.exe" /config:"C:\Users\baga\source\repos\CoreWebApp\.vs\config\applicationhost.config" /site:"CoreWebApp"
    

    To get code coverage using OpenCover,

     OpenCover.Console.exe -target:"C:\Program Files\IIS Express\iisexpress.exe" -targetargs:"/config:""C:\Users\baga\source\repos\CoreWebApp\.vs\config\applicationhost.config"" /site:CoreWebApp" -output:"c:\baga\Coverage.results.xml" -register:user –targetdir:"C:\Users\baga\source\repos\CoreWebApp\CoreWebApp\bin\Debug\netcoreapp2.0" -oldStyle
    

    To generate the html report

    ReportGenerator.exe -reports:"c:\baga\Coverage.*.xml" -targetdir:"Coveragehtml"