Scanning single project in .NET solution with multiple projects using SonarQube

960 views
Skip to first unread message

con...@unit-e.info

unread,
Apr 12, 2018, 3:31:39 AM4/12/18
to SonarQube

I have the following issue.
 
We have a .NET solution which contains several projects and have created a VSTS build definition per project because we don't want to build the entire solution every time there's a change in one of the individual projects.
 
Of course in this case when using SonarQube we would only want to push the metrics of that particular project / buildefinition to the SonarQube server and not of the entire solution.
By default the latter is what's happening and that is what we want to change.
 
We are using VSTS with Visual Studio 2015, SonarQube plugin version 4.1.1 and SonarQube version 6.7 (build 33306). The buildagents are running on Windows 8.1 at this time.
 
Example solution structure:
 
MainSolution

- ProjectA
- ProjectB
- ProjectC

The root sources directory for VSTS in this case is `C:\buildagent\vsts-agent\_work\19\s`

Directory structure on build agent would look like this:
 
    C:\buildagent\vsts-agent\_work\19\s\ProjectA
    C:\buildagent\vsts-agent\_work\19\s\ProjectB
    C:\buildagent\vsts-agent\_work\19\s\ProjectC
 
Let's say we have a VSTS build definition for ProjectB which only builds ProjectB.  In that case we only want to SonarQube to scan the contents of the ProjectB project.
 
I've tried several things to accomplish this but none of them worked.
 
1. sonar.inclusions / sonar.exclusions
Only seems to work on file level, not directory or project. Tried several settings and no error occurs but everything is ignored by the scanner which results in nothing being pushed to SQ
server at all.
 
2. sonar.sources
 
Setting the property sonar.sources to `C:\buildagent\vsts-agent\_work\19\s\ProjectB` looked promising but we got the error message below when running the scanner:
 
>2018-04-04T07:12:51.0538120Z INFO: Base dir: C:\buildagent\vsts-agent\_work\19\s
2018-04-04T07:12:51.0538120Z INFO: Working dir: C:\buildagent\vsts-agent\_work\19\.sonarqube\out\.sonar
2018-04-04T07:12:51.0538120Z INFO: Source paths: ProjectB
2018-04-04T07:12:51.0548120Z INFO: Source encoding: windows-1252, default locale: nl_NL
2018-04-04T07:12:51.1518136Z ERROR: Error during SonarQube Scanner execution
2018-04-04T07:12:51.1518136Z ERROR: File ProjectB/App.config can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
 
It looks like SonarQube is trying to index ProjectB twice. Once with BaseDir set to `C:\buildagent\vsts-agent\_work\19\s\ProjectB`
and once with BaseDir set to `C:\buildagent\vsts-agent\_work\19\s`
 
 
3. sonar.projectBaseDir
 
When setting the property sonar.projectBaseDir to C:\buildagent\vsts-agent\_work\19\s\ProjectB we receive below error from SonarQube.
 
>2018-04-04T07:00:51.2906744Z ERROR: Error during SonarQube Scanner execution
2018-04-04T07:00:51.2906744Z ERROR: Dir C:\buildagent\vsts-agent\_work\19\s\ProjectA should be relative to project baseDir
 
It looks like it is still trying to scan the entire VSTS root source directory `C:\buildagent\vsts-agent\_work\19\s` and not just `C:\buildagent\vsts-agent\_work\19\s\ProjectB`.
 
So the question remains. How can we make this work?

Amaury Leve

unread,
Apr 12, 2018, 6:23:39 AM4/12/18
to con...@unit-e.info, SonarQube
Hi,

We don't support partial analysis. Best way is to analyse each project individually (i.e. 3 projects on SonarQube) and to group them into an application using the portfolio (doc here: https://docs.sonarqube.org/x/8AWR).

Would it be enough for you?

Cheers,
Amaury

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/f86e90c7-7d9a-4b62-a193-a86fd8b9195e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Amaury Levé | SonarSource

Software Developer - .Net Team

http://sonarsource.com


Are you using SonarLint in your IDE? 
Message has been deleted

con...@unit-e.info

unread,
Apr 17, 2018, 9:57:25 AM4/17/18
to SonarQube
Hi,
Analyse each project individually is exactly what I'm trying todo but cannot get to work because the project is part of a solution with multiple projects. The scanner is trying to scan all the projects in the solution by default and I cannot just retrieve the sources for the one project because it might have dependencies with one or more of the other projects in the solution.

Op donderdag 12 april 2018 12:23:39 UTC+2 schreef Amaury Leve:

Amaury Leve

unread,
Apr 17, 2018, 10:18:44 AM4/17/18
to con...@unit-e.info, SonarQube
Hi,

I am having some trouble to understand your setup.

What I understand (correct me if I am wrong):

1. You have only 1 solution referencing 3 projects. 

2. The 3 projects are built in 3 different build definitions.

3. The 3 build definitions use the solution defined in #1? Or are you building only the projects? If you are building the projects separately, I assume that they are isolated (i.e. they don't reference each others), am I right?

Cheers,
Amaury


For more options, visit https://groups.google.com/d/optout.

con...@unit-e.info

unread,
Apr 23, 2018, 5:07:28 AM4/23/18
to SonarQube
HI,

1. Correct.
2. Correct.
3. I'm only building one project per buildefinition, not the entire solution. In some cases projects can have references to other projects in the solution, but not always.

Regards,
Bart

Op dinsdag 17 april 2018 16:18:44 UTC+2 schreef Amaury Leve:

con...@unit-e.info

unread,
May 17, 2018, 4:39:45 AM5/17/18
to SonarQube
We've made the decision to split up solutions with multiple projects into multiple solutions and base our VSTS build definitions on single solutions in stead of projects. That is probably the best approach.

Op donderdag 12 april 2018 09:31:39 UTC+2 schreef con...@unit-e.info:
Reply all
Reply to author
Forward
0 new messages