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

半城伤御伤魂 提交于 2019-12-03 14:20:41

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!