.NET: Include Test Projects in Sonar Analysis

which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

  • Self hosted SonarQube Community Edition: v7.9.2 (build 30863)
  • I am realizing my automatic Build using Cake, these are the relevant versions for Sonar:
    • Cake (including Cake.Tool, Cake.Common, Cake.Core, …): v1.1.0 (latest)
    • Cake.Sonar: v1.1.25 (latest)
    • MSBuild.SonarQube.Runner.Tool: v4.8.0 (latest)

what are you trying to achieve

I want to analyze my larger WPF .NET Framework 4.7.2 Project (uses the new csproj Format)

what have you tried so far to achieve this

Set up my automatic build in a way that this order is respected:

  • sonar begin {arguments}
  • Coverage (dotCover) and Tests (dotnet test)
  • sonar end {arguments}

This works fine for this (and many other projects) already. Only problem I have:
The CLI indexes 2000+ files (according to the logs), but on the Website (of the self hosted SonarQube instance) there are only like 140+ files present.

After some digging around I found out that these 140+ files belong to the Product projects listed in the .sonarqube\out\ProjectInfo.log file. The other files belong to the Test projects.
Because this project has “grown historically”, the implementation and tests are in the same projects, so the test projects need to be analyzed as well (for the time being, because with the project work we don’t have the time and ability to pull apart the implementation and tests at the moment)

With that knowledge I stumbled upon this Argument that you can pass to sonar begin:


which is set to true by default (found it here).

I tried to set this in my automatic build, but it didnt change anything.
Is there anything else that I can do?

Thanks for your help!

A colleague shared this with me:

Basically: You can use <SonarQubeTestProject>false</SonarQubeTestProject> (in a PropertyGroup) in the csprojs that you dont want to be Test-Projects. This works well for my case as well.

1 Like

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