"The branch has no lines of code" problem for just one out of 30 projects

Must-share information:

  • SonarQube 7.9.1, SonarQube Plugin for Azure DevOps 4.21.0, SonarScanner for MSBuild (5.2.1 according to pipeline logs).
  • I want to run SQ code analysis on a branch from an Azure DevOps build pipeline (C# code), but all sources seem skipped during analysis. Additionally, SonarQube says “The ‘X’ branch has no lines of code”.
  • I have successfully configured 30+ similar projects with practically the same settings but failed just on this one.

This problem is very consistent and appears only for one particular project out of all that we’ve covered with analysis. More things I have already tried:

  • comparing the pipelines in Azure DevOps used for the failing project and for the working projects, but there are no significant differences. In fact, the build steps including SonarQube tasks are reused (as a task group), so apart from project paths the settings are the same
  • following advice from several similar issues on the Community forum here
  • creating a new project in SonarQube admin panel and running a fresh analysis
  • recreating/changing the pipeline in Azure Devops

None of the above helps. What I notice in build logs is that the sources are detected but seemingly treated as test code:

03822CB2-365B-4B9B-AC7B-B6C459B23CC7.sonar.tests=\
"E:\\va2\\_work\\1718\\s\\src\\MyProject\\SomeFile.cs",\
"E:\\va2\\_work\\1718\\s\\src\\MyProject\\Constants\\SomeFile1.cs",\
"E:\\va2\\_work\\1718\\s\\src\\MyProject\\Constants\\SomeFile2.cs",\
"E:\\va2\\_work\\1718\\s\\src\\MyProject\\Constants\\SomeFile3.cs",\
"E:\\va2\\_work\\1718\\s\\src\\MyProject\\Constants\\SomeFile4.cs",\
"E:\\va2\\_work\\1718\\s\\src\\MyProject\\Constants\\SomeFile5.cs",\
....

I don’t know if this is a real problem, but it caught my attention. The other projects have the sources under sonar.sources rather than sonar.tests. I have tried to set the settings explicitly, e.g. sonar.sources, sonar.tests, sonar.test.exclusions, etc., but it doesn’t help.

What else controls what files are put in the “tests” vs “sources” buckets?

Hi,

Welcome to the community!

7.9.1 is past EOL. Since that version, a lot has happened, including some improvements to how we detect which projects are tests in C#. You should upgrade to either the latest version or the current LTS at your earliest convenience.

 
HTH,
Ann

Hi,

We’ve updated SonarQube to 8.9.1. but it didn’t help. I found what the problem was, however: all projects in this particular repository were referencing xunit framework assemblies (by mistake). Therefore all code was treated as test code. The fix was to remove the PackageReference to xunit in non-test projects.

There’s a documentation page explaining how projects are categorized as test or production code.

Hoping this helps someone else…

1 Like

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