具有MSBuild Runner的C#插件的SonarQube不排除在外 [英] SonarQube with C# plugin with MSBuild Runner does not take exclusions

查看:150
本文介绍了具有MSBuild Runner的C#插件的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 的说明,我进行了设置跑步者的电话中有一个简单的排除规则:

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"

我发现跑步者创建了一个sonar-project.properties文件,该文件包含位于databases文件夹中的许多文件:

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扫描器用于所有其他语言.

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>

希望有帮助!

来源

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

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