Scan of the .NET project fails with the "can't be indexed twice" error

I’m scanning a .net core project with the SonarScanner for MSBuild on a TeamCity build server. It’s an official plugin developed by Jetbrains. It is running SonarQube Scanner

Scanning has been working fine for quite long time with no hickups until recently it started to fail for many projects with the following error in the log:

ERROR: Error during SonarQube Scanner execution
ERROR: File src/Customer.Abstractions/Enums/OwnerType.cs can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files*

Begin analysis command is the following:

MSBuild.SonarQube.Runner.exe "/d:project.home=." "/[](" "/k:Customer_project" "/n:Customer" "/v:209" "/d:sonar.login=????" /d:sonar.cs.opencover.reportsPaths=**\**\coverage.opencover.xml /d:sonar.exclusions=**\libs\**\* /d:sonar.sources=src /d:sonar.qualitygate.wait=true begin

I’m setting custom sonar.exclusions, sonar.cs.opencover.reportsPaths parameter values, so that’s controlled. But I’m suspicious about the sonar.sources parameter which seems to be automatically set and I read in some community threads that it’s advised not to use sources and exclusions parameters at the same time.

So any ideas, suggestions how to fix or workaround this issue?

Hey there.

  • Make sure you are using the latest version of the SonarScanner for .NET. Using MSBuild.SonarQube.Runner.exe hints at this being an older version. You should always use the latest version of the scanner.
  • Do not use sonar.sources when using the SonarScanner for .NET. It causes issues like the above (the scanner will sort out what files to scan based on the structure of the project). It is fine to set sonar.exclusions and sonar.cs.opencover.reportsPaths

If you still face the issue after upgrading the scanner and removing sonar.sources from the command line, feel free to come back to us.

Hello Colin,

I just updated SonarScanner to the latest available version in your link. Problem still persists. But I have noticed that TeamCity Sonar plugin apparently adds that sonar.sources parameter automatically. I’m able to override it by passing my own value, but by default it somehow adds it’s own value (src in our case).

So do you have any other idea what could be done to make it work?