简体   繁体   中英

SonarQube with C# plugin with MSBuild Runner does not take exclusions

Currently I have an instance of SonarQube 5.1.2 with C# plugin and MSBuild runner in order to analyze a 1.200.000 LOC project. I intend to reduce the classes that are analyzed, I created a sonar.properties file with the line

sonar.exclusions=**/Databases/**/*.*

but after reading the log from the analysis, files inside the Databases folder were analyzed. following the instructions from Eric Starr , I set this simple exclusion rule in the call of the runner:

"C:\sonarqube-5.1.2\bin\MSBuild.SonarQube.Runner.exe" begin /k:MyProject /n:MyProject /v:2 /d:sonar.exclusions="file:C:\codesource\Databases/**/*.*" /d:sonar.scm.provider=tfvc /d:sonar.tfvc.username=*************  /d:sonar.tfvc.password.secured={aes}*************************** "/d:sonar.cs.vscoveragexml.reportsPaths=C:\codesource\CodeCoverage\Results.coveragexml"

I found that the runner creates a sonar-project.properties file, and it contains a lot of files located in the databases folder:

BC78C8C4-8ECD-47CB-9781-F621AE109FE4.sonar.projectName=myDatabase
BC78C8C4-8ECD-47CB-9781-F621AE109FE4.sonar.projectBaseDir=BC78C8C4-8ECD-47CB-9781-F621AE109FE4.sonar.projectName=myDatabase
BC78C8C4-8ECD-47CB-9781-F621AE109FE4.sonar.projectBaseDir=C:\\codesource\\Databases\\myDatabase
BC78C8C4-8ECD-47CB-9781-F621AE109FE4.sonar.sources=\
C:\\codesource\\Databases\\myDatabase\\Scripts\\PreDeployment\\PATCH_20150527_01.sql,\
C:\\codesource\\Databases\\myDatabase\\Scripts\\PreDeployment\\ROCOMMON.DBVERSION.sql,\
,\.....

as I understood, there should be no files in the databases folder. Am I wrong?

You are using the SonarQube Scanner for MSBuild which is very different from the regular SonarQube Scanner used for all other languages.

The sonar.exclude line that you are trying to use would only work if you would use the regular SonarQube scanner, because that takes in the Sonar-project.properties file. The SonarQube Scanner for MSBuild only has a SonarQube.Analysis.Xml file that contains project-related settings that you can tweak.

You can use couple of overwriting strategies for the SonarQube.Analysis.Xml file:

  • A project-specific property defined in the MSBuild *.*proj file (corresponding to a SonarQube module) can override:
  • A property defined in the command line (/d:propertyName=value) has which can override:
  • A property defined in the SonarQube.Analysis.xml configuration file
  • A property defined in the SonarQube User Interface at project level which can override everything
  • A property defined in the SonarQube User Interface at global level which can't override anything

To exclude specific folders or extensions from your Solution:

You need to add the excludes into each individual projects' .csproj file. Here's the syntax which you should use within the main root node, called <Project...> and into one of the targets, preferably <Target Name="BeforeBuild"> . Hope the syntax below is self-explanetory enough, but in case it isn't, please leave a comment under this answer and I'll update it right away.

<Target Name="BeforeBuild">
    <ItemGroup>
          <SonarQubeSetting Include="sonar.exclusions">
              <Value>**/Databases/**/*</Value>
          </SonarQubeSetting>
      </ItemGroup>
  </Target>

Hope it helps!

Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM