SonarQube Analysis Missing Entire Projects' Lines of Code

Currently running version

We have multiple .NET Core solutions running SonarQube analysis and I have therefore made a generic yml pipeline in Azure DevOps to make things simpler to set up a new project. Point being, other than the parameters being passed in, they all run the same thing.

In every solution but one so far, everything works as expected. When I go to the Code tab of these projects, I can see lines of code matching what I would expect.

Now, for some reason, this one solution is missing all lines of code from certain projects, and is including files that should be excluded (an extra 152k files) in the Web project. When I go into a project with no lines of code it has the files in there, but it is as if they just weren’t analyzed for whatever reason. And the wwwroot/lib folder that should be excluded is not.

So, I thought maybe there is a bug in the yml file they are all using that just affects this one solution, but I don’t see where.

Then I looked at each project’s yml file at the parameters, seeing as how that is the only difference between solutions, but I see nothing that would cause a problem when it works in all the others.
Solution that works:

Solution that does not:

I have analyzed the build logs and noticed one weird thing in the one that is not working correctly. You can see it builds the Data project and detects some issues, but the other projects get processed successfully instantly without any issues detected. These are the projects that also do not show any code in the Code view in an earlier screenshot. It is almost as if SonarQube is not running on them whatsoever.

Additionally, although the project’s code coverage is somewhere around 90%, SonarQube has nothing for coverage or tests.

I can send logs in private message on request, please help. :slight_smile:

Hey there.

We’d need some verbose logs in order to help you.

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        # Applies to SonarQubePrepare as well
        - task: SonarCloudPrepare@1
              SonarCloud: 'sonarcloud'
              organization: 'zucchinibreadco'
              scannerMode: 'MSBuild'
              projectKey: 'zuchhinibreadco_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild verbose logs

MsBuild.exe /t:Rebuild /v:d


dotnet build -v:diag

I can also raise a private message so you can share them privately before being passed to the right team.

Hey Colin, thanks for the response. Please start a private message with me and I’d be happy to send over the logs.

Thanks Colin for the help!

After enabling verbose logging for the dotnet build and sonarqube analyze steps I was able to see that the projects were being treated as test projects. This was because a project that all other projects referenced had a reference to Moq. You can see this in the build output: (Project.API.csproj) project is evaluated as a test project based on the 'Moq' reference. (TaskId:124)

Therefore, with the help of this documentation we set the projects we wanted to analyze explicitly by adding <SonarQubeTestProject>false</SonarQubeTestProject> to the csproj files. Then it all behaved as exptected!

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