question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code coverage not working with MVC/Razor applications targeting ASP.NET 6 preview 3+

See original GitHub issue

In .NET 6 preview 3, the Razor compiler was changed to use a Roslyn source generator instead of compiling a separate .Views assembly (announcement).

Similar to #1084, this causes coverlet to be unable to instrument the application’s assembly due to seemingly missing source files emitted into the assembly/PDB for the views:

[coverlet] Unable to instrument module: C:\Coding\martincostello\api\tests\API.Tests\bin\debug\net6.0\API.dll, pdb without local source files, [C:\Coding\martincostello\api\src\API\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\_Views_Docs_Index.cshtml.cs]

At first I thought this might have been caused by https://github.com/dotnet/sdk/pull/16777, but having updated to a nightly build of the preview 4 SDK containing the fix for that issue to verify that (6.0.100-preview.4.21210.1), code coverage is still not reported.

I’m not sure if this is an SDK issue (missing .g.cs suffix), a coverlet issue, or both, so I’m opening this issue here and ~will open a separate issue referencing this one~ have opened dotnet/sdk#16835 in the dotnet/sdk repo.

To replicate the issue and generate an MSBuild binary log file with the coverlet logging present, run the following commands:

git clone https://github.com/martincostello/api.git martincostello-api
cd martincostello-api
git checkout 39867b25cc6faccaa85a3091c2a8dfa58dad6975
./build.ps1 -SkipTests
dotnet test tests/API.Tests -c debug -verbosity:diagnostic -bl:msbuild.binlog -noconsolelogger

You can then open the msbuild.binlog file in MSBuild Structured Log Viewer and search for [coverlet] to find the log message.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
martincostellocommented, Jun 17, 2021

As of .NET 6 preview 5, you can workaround this issue by adding the following to the .csproj file for any project that contains Razor views:

<PropertyGroup>
  <_UseRazorSourceGenerator>false</_UseRazorSourceGenerator>
</PropertyGroup>
1reaction
martincostellocommented, Jul 15, 2021

In preview 6 the workaround changes to:

<PropertyGroup>
  <UseRazorSourceGenerator>false</UseRazorSourceGenerator>
</PropertyGroup>
Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core updates in .NET 6 Preview 3
NET 6 Preview 3 is now available and includes many great new improvements to ASP.NET Core. Here's what's new in this preview release:....
Read more >
VS2015 Code Coverage not working with tests in ASP.NET ...
I'm able to get code coverage with OpenCover 4.6.166 using this configuration : project.json sample. { "version": "1.0.0-*", "dependencies": ...
Read more >
Code coverage doesn't work for .NET Core 3.1 projects
I'm having the same issue. I have 2 apps, one is a new .NET Core 3.1 app and doesn't show code coverage. The...
Read more >
Hot Reload for .NET 6 in Rider 2021.3
With JetBrains Rider 2021.3, you can now take advantage of Hot Reload if you are targeting .NET 6! You can make targeted changes...
Read more >
Visual Studio
Run your application to make sure there are no issues with Visual Studio 2019 Preview or .NET Core 5. You should see default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found