Relationship between projectBaseDir, sources, and exclusions

Version of SonarQube:
Community Edition Version 7.6 (build 21501)

Version of Sonar-Scanner-MSBuild:

Build environment:
Windows 10
MSBuild.exe from Visual Studio 2017

Version of MSBuild:
Microsoft ® Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright © Microsoft Corporation. All rights reserved.

I am trying to analyze some large, complex C# projects. On one of them, I am running into errors like this:

File foo.cs can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files.

The project is structured with a SLN file in one directory, with each of the components in subdirectories under that. Each of the components has a CSPROJ file.

I have been trying various values of sonar.projectBaseDir, sonar.sources, and sonar.exclusions to resolve the issue, without success.

One thing I’m not clear on from the documentation–how do the sonar.projectBaseDir, sonar.sources, and sonar.exclusions values relate to each other? Is the value for sonar.sources relative to the value of sonar.projectBaseDir? Is the value for sonar.exclusions relative to sonar.sources? Are absolute paths permissible (or recommended) for any of them?

Thanks for your help.


If you’re using SonarScanner for MSBuild, you shouldn’t need to set any of those properties; it should all be set for you automatically from eavesdropping on your build. Have you tried that? And if so, what happened?

To answer your question:

  • sonar.projectBaseDir is used to point analysis at a different directory than the one analysis is fired from. This should only be set explicitly (it’s set implicitly to . by analysis if you don’t provide a value) in pretty pointy corner cases. In the vast majority of cases you should be analyzing from your project root and should not need to set this.
  • sonar.sources defines where in sonar.projectBaseDir to find your project’s source files. Yes, it should be relative.
  • sonar.exclusions should be set from the UI rather than from analysis settings. That said, it is used to say "ignore this subset of files in sonar.sources"



Removing them resolved the “Can’t be indexed twice” issue. And thank you for the explanation.


1 Like