Not analyzing .cs files - only .cshtml, js, etc for .NET 5 MVC (with Razor compilation)

SonarQube, version:, developer edition

We have a .NET 5 web app which is built using Azure DevOps and we are using SonarQube to analyze the source code. However, with this project, SonarQube is not analyzing .cs files. This files are just shown as: “Lines of code —”.
.cshtml, css, js, etc files are analyzed and correct number of lines shown.
We are using the SonarQube plugin for Azure Devops.

Any suggestion on why .cs files are not picked up?


Does this seem relevant?


@ganncamp thanks for the link but I don’t think so. We are using The Azure DevOps SonarQube which according to the docs: “Since version 5.0, the SonarScanner for MSBuild is now the SonarScanner for .NET.” So we are indeed using SonarScanner for .NET by using the MSBuild option.


I’m not an expert in this area, so let’s see what they say when they arrive.


I just tried running SonarScanner locally against this project to rule out any Azure DevOps issues and it’s the same problem, running this from the docs:

dotnet <path to SonarScanner.MSBuild.dll> begin /k:"project-key" /d:sonar.login="<token>"
dotnet build <path to solution.sln>
dotnet <path to SonarScanner.MSBuild.dll> end /d:sonar.login="<token>" 

Another observation: This is related to this specific project, when moving one class over into a repro project it is analyzing the code and detecting duplications, etc. This seems like a bug in SonarQube and this is kind of critical to us as we have developers that cannot finish their tasks before they are able to fix issues found by SonarQube.

Original project (ASP.NET Web App .NET 5):

Repro project (Console App, .NET 5):

Additional update: turns out this is easy to reproduce:

  1. Create new ASP.NET Core Web App, .NET Core 5 (MVC)
  2. Run SonnarScanner.MSBuild

Again, this is a brand new project, no modifications.

Thank you @nicklasjepsen , I’ve managed to reproduce it. I’ve opened Not generating metadata files for ASP .NET 5 MVC project · Issue #4709 · SonarSource/sonar-dotnet · GitHub and we’re going to investigate this.

As a clarification, the C# code analysis is working - issues are being raised, however we are not generating the necessary metadata for syntax highlighting and metrics. You can see on your Program.cs that you have a code smell. Also, you should see the analysis warnings in the logs - the files do get analyzed.