asp.net-core.net-corepdb-filesopencover

OpenCover Cannot instrument .exe as no PDB/MDB could be loaded


I have a ASP.NET Core project(target to .NETFramework,Version=v4.6.1) that was working under VS2015. When I converted to VS2017 I am not able to make OpenCover working. When build.PS1 runs

C:\OpenCover\4.6.519\tools\OpenCover.Console.exe -register:user -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:" test "C:\GitRepos\AdminPortal\Source\test\AdminPortal.UnitTests\AdminPortal.UnitTests.csproj" " -output:"C:\GitRepos\AdminPortal\Build..\OUTPUT\Test-Output\projectCoverageReport.xml" -log:Verbose -oldStyle

the output (truncated for brevity) is the following:

C:\OpenCover\4.6.519\tools\OpenCover.Console.exe -register:user -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:" test "C:\GitRepos\AdminPortal\Source\test\AdminPortal.UnitTests\AdminPortal.UnitTests.csproj" " -output:"C:\GitRepos\AdminPortal\Build..\OUTPUT\Test-Output\projectCoverageReport.xml" -log:Verbose -oldStyle Executing: C:\Program Files\dotnet\dotnet.exe
Cannot instrument C:\Program Files\dotnet\sdk\1.0.3\dotnet.dll as no PDB/MDB could be loaded ... Cannot instrument C:\Program Files\dotnet\sdk\1.0.3\Microsoft.TestPlatform.Build.dll as no PDB/MDB could be loaded
Build started, please wait...
...
Cannot instrument C:\Program Files\dotnet\sdk\1.0.3\NuGet.Packaging.dll as no PDB/MDB could be loaded
Cannot instrument RefEmit_InMemoryManifestModule as no PDB/MDB could be loaded Build completed.

Test run for C:\GitRepos\AdminPortal\Source\test\AdminPortal.UnitTests\bin\Debug\net461\AdminPortal.UnitTests.dll(.NETFramework,Version=v4.6.1) Cannot instrument C:\Program Files\dotnet\sdk\1.0.3\vstest.console.dll as no PDB/MDB could be loaded
Cannot instrument C:\Program Files\dotnet\sdk\1.0.3\Microsoft.TestPlatform.CoreUtilities.dll as no PDB/MDB could be loaded
Cannot instrument C:\Program Files\dotnet\sdk\1.0.3\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll as no PDB/MDB could be loaded Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0 Copyright (c) Microsoft Corporation. All rights reserved.

Cannot instrument RefEmit_InMemoryManifestModule as no PDB/MDB could be loaded Build completed. Test run for C:\GitRepos\AdminPortal\Source\test\AdminPortal.UnitTests\bin\Debug\net461\AdminPortal.UnitTests.dll(.NETFramework,Version=v4.6.1) Cannot instrument C:\Program Files\dotnet\sdk\1.0.3\vstest.console.dll as no PDB/MDB could be loaded Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0 Copyright (c) Microsoft Corporation. All rights reserved. Starting test execution, please wait...
... Cannot instrument C:\Program Files\dotnet\sdk\1.0.3\TestHost\msdia140typelib_clr0200.dll as no PDB/MDB could be loaded
Cannot instrument C:\GitRepos\AdminPortal\Source\test\AdminPortal.UnitTests\bin\Debug\net461\AdminPortal.exe as no PDB/MDB could be loaded ...

Total tests: 39. Passed: 37. Failed: 0. Skipped: 2. Test Run Successful. Test execution time: 6.4838 Seconds

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.

I have the .PDB files in bin folder (e.g. C:\GitRepos\AdminPortal\Source\test\AdminPortal.UnitTests\bin\Debug\net461\AdminPortal.pdb), so I don't know why opencover couldn't load it. What could be the reason?

I tried to specify -targetdir:(as suggested here ) and -oldStyle , but it has no difference.
I also tried to specify -searchdirs: (from https://github.com/sawilde/opencover/wiki/Usage) and re-register profiler regsvr32 /n /i:user C:OpenCover.4.5.3723\x86\OpenCover.Profiler.dll (From OpenCover/NUnit can't find PDB files) - also make no difference.

Is it related to new portable PDB format mentioned in https://github.com/OpenCover/opencover/issues/610 ?
But I target NETFramework v4.6.1, not Core 1.1. Can I explicitly specify to dotnet test or msbuild, which PDB format to use?

Is any tool available to show, does the .PDB file has old or new format ? I tried https://github.com/Microsoft/microsoft-pdb/blob/master/cvdump/cvdump.exe as suggested at Reading a .pdb file, but it does not return anything.


Solution

  • In unrelated discussion https://developercommunity.visualstudio.com/content/problem/15197/vs2017rc-locks-files-in-obj-folder-blocking-builds.html it was suggested to Change the PDB format in the project properties from Portable PDB to Full PDB.
    If you prefer to use UI, in Visual Studio open Project Properties->Build ->Advanced->Output->Debugging Information change to Full from Portable. It will add to csproj file setting with specific build condition

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.6|AnyCPU'">
        <DebugType>full</DebugType>
        <DebugSymbols>True</DebugSymbols>
      </PropertyGroup>
    

    Normally you want to apply it for all options, so Remove the condition to have just the following (You can just paste the PropertyGroup below to your .csproj, if you didn't use Visual Studio before)

    <PropertyGroup >
        <DebugType>full</DebugType>
        <DebugSymbols>True</DebugSymbols>
      </PropertyGroup>
    

    And OpenCover will be able to instrument your projects.

    Update 19 Apr 2019: As OpenCover still doesn’t have .net core support #595, consider to use CoverLet, that has OpenCover compatible output format.