.NET Core Sonar analyzing result: The main branch has no lines of code

Hello! We have a .Net Core repository and I’d like to test our default branch (called develop) by Sonar scanner.
I renamed the “main branch” to develop in the sonarqube server.

Here is the project structure:

<Project>
     |-Application.Integration.Test.
     |-Sonar.Test
     |-src|
           - Application...
           - Domain...
     |-tests
  • I’ve set the SourceSource File Inclusions (relative from the Sonar.Test project).:
    • ../src,
    • ../Application.Integration.Test
  • and Source File Exclusions.:
    • ../src/WebUI/wwwroot/**,
    • **/*.xml.. and so on…
  • I execute the scanner in the Sonar.Test project.
  • After scanning I got the message from sonarqube server:
    • “The main branch has no lines of code”
  • I found a message in the scanner report:
    • INFO: 0 files indexed
      INFO: 728 files ignored because of inclusion/exclusion patterns

I’ve tried so set the SourceSource File Inclusions so many way. But I always get same message.
These are the versions:
dotnet-sonarscanner version: 8.0.3
SonarQube server version: 9.9.6 (ZIP)

What am I doing wrong? Could anyone help to me? Thanks,
Zoltan

Hi Zoltan,

Let’s take a step back because it’s very unusual to need both inclusions and exclusions.

So. What is sonar.sources set to? Given your project structure, I would expect to see it set like so: sonar.sources=src.

What is Application.Integration.Test? Is that a source file? Or a coverage report? You list an exclusion of

But you don’t show WebUI in your structure. Where is it actually located?

 
Ann

Hi Ann! Thanks for your support.

Our plan was to analyze the contents of the src folder, including its subfolders, except for the wwwroot and 3rdPartyLibs subfolders. (those are full of 3rd party libaries)

So we set the analysis scope this way:

  • sonar.sources set to ../src
  • sonar.exclusions set to ../src/WebUI/wwwroot/**, ../src/Infrastructure/3rdPartyLibs/** and **/*.xml

The wwwroot and 3rdPartyLibs is under the src folders (see the relative path before)
I will remove the Application.Integration.Test from sonar.source.

Hi,

Where is analysis being run from?

Your use of ../ in this context is highly unusual. I’ve seen ./, which while completely superfluous, is a harmless notation that means “start from this current directory”. But ../ means “go to the parent directory of the current directory, and…”. So its use here implies that you’re triggering analysis from a sister directory of src. Is that the case? And if so, why?

If it’s not, I would expect something like:

sonar.sources=src
sonar.exclusions=WebUI/wwwroot/**/*,Infrastructure/3rdPartyLibs/**/*,**/*.xml

Note that once you set the source file directory to src, exclusion patterns should be set relative to that.

 
HTH,
Ann

We liked to separate the config of the sonarqube into a “sister directory” as you said.
We didn’t know that it is not possible or “bad practise”
If your opinion is, its a bad practise and we should run the scanner from the root, than we will move the sonar config to the root.

Hi,

Yes, it really is best practice to run analysis from the project root, and it will certainly simplify your configurations.

 
Ann

Ok, than we will try to run scanner from root. I will give you feedback about the process later.
Have a great week,

Zoltan