That’s a shame. The docs definitely said duplications like this would not be counted - I guess that was changed at some point.
To help anyone else in the future, I’ve achieved this with the following approach:
-
Within the
csproj
file which is being counted twice by SonarCloud, add a custom property wrappingSonarQubeExclude
<PropertyGroup Condition="'$(SonarQubeExcludeDuplicates)' == 'true'"> <SonarQubeExclude>true</SonarQubeExclude> </PropertyGroup>
-
During your CI build, pick one of the jobs to apply the exclusion by passing the
SonarQubeExcludeDuplicates
flag tomsbuild
ordotnet
MSBuild -p:SonarQubeExcludeDuplicates="true" MySolution.sln dotnet build -p:SonarQubeExcludeDuplicates="true" MySolution.sln
A good way to check that this is working as intended locally is to run the Sonar Scanner in Simulation mode by adding <Property Name="sonar.scanner.dumpToFile">sonar-scanner.log</Property>
to the SonarQube.Analysis.xml
. Run the begin, build, and end commands and then find the .sonarqube/out/ProjectInfo.log
file. If it worked, the project will be listed under the “Skipped projects” section.