Skip to content

Coverlet code coverage not working with MVC/Razor applications targeting ASP.NET 6 preview 3+ #31719

@martincostello

Description

@martincostello

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

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]

This Pull Request shows the missing coverage in the GitHub Actions build logs.

At first I thought this might have been caused by dotnet/sdk#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 (say missing .g.cs suffixes like fixed by dotnet/sdk#16777), a coverlet issue, or both, so I'm opening this issue here and have also opened coverlet-coverage/coverlet#1140 reporting the same problem.

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.

/cc @captainsafia @pranavkm

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions