带有 C# 插件和 MSBuild Runner 的 SonarQube 不会排除 [英] SonarQube with C# plugin with MSBuild Runner does not take exclusions

查看:41
本文介绍了带有 C# 插件和 MSBuild Runner 的 SonarQube 不会排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个带有 C# 插件和 MSBuild 运行器的 SonarQube 5.1.2 实例,以便分析 1.200.000 LOC 项目.我打算减少要分析的类,我创建了一个带有

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/**/*.*

但是在从分析中读取日志后,Databases 文件夹中的文件被分析了.按照 Eric Starr 的说明,我设置了runner 调用中的这个简单的排除规则:

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.2inMSBuild.SonarQube.Runner.exe" begin /k:MyProject /n:MyProject /v:2 /d:sonar.exclusions="file:C:codesourceDatabases/**/*.*" /d:sonar.scm.provider=tfvc /d:sonar.tfvc.username=*************  /d:sonar.tfvc.password.secured={aes}*************************** "/d:sonar.cs.vscoveragexml.reportsPaths=C:codesourceCodeCoverageResults.coveragexml"

我发现跑步者创建了一个 sonar-project.properties 文件,它包含很多位于数据库文件夹中的文件:

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?

推荐答案

您正在使用 SonarQube Scanner for MSBuild 与常规 SonarQube 扫描仪有很大不同a> 用于所有其他语言.

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

您尝试使用的 sonar.exclude 行仅在您使用常规 SonarQube 扫描仪时才有效,因为它包含 Sonar-project.properties 文件.适用于 MSBuild 的 SonarQube 扫描仪只有一个 SonarQube.Analysis.Xml 文件,其中包含您可以调整的项目相关设置.

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.

您可以对 SonarQube.Analysis.Xml 文件使用几种覆盖策略:

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

  • MSBuild *.*proj 文件中定义的项目特定属性(对应于 SonarQube 模块)可以覆盖:
  • 在命令行中定义的属性 (/d:propertyName=value) 具有可以覆盖:
  • SonarQube.Analysis.xml 配置文件中定义的属性
  • 在项目级别的 SonarQube 用户界面中定义的属性,可以覆盖所有内容
  • 在 SonarQube 用户界面中定义的全局级别的属性,不能覆盖任何内容

要从您的解决方案中排除特定文件夹或扩展:

您需要将排除项添加到每个单独项目的 .csproj 文件中.这是您应该在主根节点中使用的语法,称为 <Project...> 并用于目标之一,最好是 <Target Name="BeforeBuild">.希望下面的语法足够不言自明,但如果不是,请在此答案下发表评论,我会立即更新.

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>

希望对你有帮助!

来源

这篇关于带有 C# 插件和 MSBuild Runner 的 SonarQube 不会排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆