1

I have a C# project that also includes som test user interface that should not be investigated by SonarCube, (SonarCube is invoked by teamcity)

I would like the following folders and all content to be ignored by SonarCube

  • .\src\ExamplePredictionCascadingResourceProvider (should be ignored by local rule)
  • .\src\TestPredictionCascadingGUI (should be ignored by local rule)
  • .\src\VM.PredictionCascade.Tests (should be ignored by global rule **/Tests/.cs)

I have added the first folder in the userinterface for the local sonarcube project in sonar.exclusions, but there are still issues from the sourcecode in that folder.

In the SonarQubeAnalysisConfig.xml the value seems to end up fine

  • <Property Name="sonar.exclusions">**/ExamplePredictionCascadingResourceProvider/**/*</Property> Local example file that should be ignored

besides the project exlusion there are the following global exclusions

  • <Property Name="sonar.global.exclusions">**/bin/x64/,/bin/x86/,/packages/,/obj/x64/,/obj/x86/,/src//bin/,/src//obj/,/AssemblyInfoAppend.cs,**/AssemblyInfo.cs</Property>
  • <Property Name="sonar.global.test.exclusions">**/Test/.cs,**/Tests/.cs</Property> example that should be ignored global exlusion rule

for other projects the same value of 'sonar.global.test.exclusions' seems to work

so I am quite puzzled, and don't really know where to start to investigate why the files are inlcluded... Could it be because I changed the 'exclusions' after creating the project, and then sonarcube remembers the previous issues?

Any hints on what the problem is or what to investigate?

buildcomplete
  • 552
  • 2
  • 15

1 Answers1

1

By looking into the teamcity buildlog, I just realized that SonarQube applies those exclusion rules assuming the base directory to be the directory for the project that is being analyzed, which means there is no clear way on excluding all the files within ExamplePredictionCascadingResourceProvider folder. In other words, when SonarQube starts to analyze files for ExamplePredictionCascadingResourceProvider project, it sets the base directory to this folder, and hence it cannot match any files with given patterns to exclude.

As a solution, you should use a pattern which matches all the file names within ExamplePredictionCascadingResourceProvider folder. Assuming that all the files within that folder start with "Example" it should suffice to add "Example*.cs" to the exclusion rules.

A good usecase for setting an exclusion rule on the SonarQube server which applies to all the projects, is to have "**/AssemblyInfo.cs", since AssemblyInfo.cs exists for all c# projects under the Properties subfolder within the project folder.

I also recommend taking a look at the answer to SonarQube with C# plugin with MSBuild Runner does not take exclusions, if you want to specify the exclusion rule locally in your project rather than on the SonarQube server (which makes more sense for your specific scenario, since this rule is project specific).

masih
  • 598
  • 1
  • 6
  • 10