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.

This problem got fixed in SonarScanner for .Net 5.3.1.

Thank you for reporting it.

1 Like

Thanks Andrei!

We are using Azure DevOps to run the SonarScanner on our projects. It seems like this issue is still not fixed when running through DevOps as we still don’t see the metadata in SonarQube.

Do we need to do anything to force DevOps to use the newly released version?

A post was split to a new topic: .NET 5 Razor Component Library - no metrics

The Azure DevOps extension should be released this week with the new scanner embedded. You can watch the releases here:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.