Can I use dotnet sonarscanner to report to multiple projects?

I need to setup Sonarqube for a C# solution which contains two “independent” projects. I can’t split up the solution because of “political reasons”. I found out that I can create two Sonarqube projects and use sonar.sources and sonar.inclusion to associate the correct C# projects to them.

How can I “fill” the two projects with data in a single build run? I’m using sonarscanner for dotnet like this:

dotnet sonarscanner begin /k:"[Project]"

but it only accepts a single project. Can I start sonarscanner twice before I run the build? Any other tricks?


Welcome to the community!

Are these projects part of the same solution? There’s a bit of a nomenclature clash when you put SonarQube and .NET together. If both of your .NET projects are part of the same .NET solution, then that’s one SonarQube project (confused yet? :crazy_face:)

So you would only need to run the scanner once for the solution.

Does that make sense?


Sry for the late answer. I was busy in another project and just came back to this topic.

Basically we have a single Gitlab repo with a single .NET solution, but the solution contains .NET projects of two independent teams. Therefor I’d like to have two Sonarqube projects. One for team A and one for team B. The challenge is that the solution is build by a single CI pipeline. This means the entire solution is build, but some analyze should go to the Sonarqube project of team A and some should go to the Sonarqube project of team B

I can determine both code parts with source/exclude statements, but I need to know how I can define two target projects for the same pipeline.


Your original question was about populating two different SonarQube projects from one analysis. That’s not possible. You’ll need to do two different build/analysis runs, passing your source/exclude statements and a different project key for each one.


Thanks for the answer. That’s unfortunate. Do you see any other option to solve my problem?

Hi @Sonar31,

It is an interesting topic.

Did you think about modifying your pipeline? It could be something like

If team A commit => dotnet sonarscanner begin /k:"[ProjectA]"
else => dotnet sonarscanner begin /k:"[ProjectB]"

You can still have one CI pipeline but two separate projects on SonarQube. The build stage remains no change.

Yes this could be an option I’ll keep in mind.

I found out that you can specify modules with individual sources, but it looks like it’s only supported for maven projects: SonarQube multi module maven project - Stack Overflow


#List of module identifiers

#module1 settings

#module2 settings

#module3 settings

Could this be done for C# projects too?

You have multi-modules maven projects. But I’ve never seen multi-modules C# projects.