简体   繁体   English

SonarQube MSBuild运行程序不适用于已添加到项目中的移植FxCop Roslyn规则

[英]SonarQube MSBuild runner isn't working with ported FxCop Roslyn rules added to projects

Currently we're running SonarQube analyses during our build proces. 目前,我们在构建过程中正在运行SonarQube分析。 We've wanted to run our quality profile locally in Visual Studio 2015. For this we've created a ruleset for Visual Studio and turned on the rules that were enabled in our quality profile. 我们希望在Visual Studio 2015中本地运行质量配置文件。为此,我们为Visual Studio创建了一个规则集,并打开了在质量配置文件中启用的规则。 SonarLint has an intergration for this, but the FxCop rules aren't synced (at the moment). SonarLint对此进行了整合,但是FxCop规则目前尚未同步。 When enabled FxCop rules Visual Studio freezes. 启用FxCop规则后,Visual Studio会冻结。 So this wasn't an option for us. 所以这不是我们的选择。

Another option we've tried is instead of creating a ruleset based on FxCop and Roslyn. 我们尝试过的另一个选择是代替基于FxCop和Roslyn创建规则集。 Was trying to create a roslyn only ruleset. 正在尝试创建仅Roslyn规则集。 So we've added the FxCop port to Roslyn rules NuGet package to out projects. 因此,我们已将FxCop端口添加到Roslyn规则 NuGet包中以输出项目。 But when we ran SonarQube with MSBuild Runner 2.1 we received the following error: MSBUILD : error : CA0059 : Invalid settings passed to CodeAnalysis task. See output window for details. 但是,当我们使用MSBuild Runner 2.1运行SonarQube时,收到以下错误: MSBUILD : error : CA0059 : Invalid settings passed to CodeAnalysis task. See output window for details. MSBUILD : error : CA0059 : Invalid settings passed to CodeAnalysis task. See output window for details. We get this error even when we didn't turn on these rules or use the default Microsoft Ruleset. 即使没有打开这些规则或使用默认的Microsoft Ruleset,也会出现此错误。

When I take a look at the MSBuild log I see the following (removed a lot of rules for readability): 当我查看MSBuild日志时,会看到以下内容(删除了许多可读性规则):

/rulesetdirectory:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\\Rule Sets" 
/rule:"-C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FxCop\\Rules" 
/ruleid:"-Microsoft.Performance#CA1820" 
/ruleid:"-Microsoft.Reliability#CA2002" 
/ruleid:"-Microsoft.Usage#CA1816
      -Microsoft.Usage#CA2208" 
/ruleid:"-Microsoft.Usage#CA2216"  
/searchgac /ignoreinvalidtargets 
/forceoutput /successfile /ignoregeneratedcode /saveMessagesToReport:Active,Excluded 
/timeout:120 
/reportMissingIndirectAssemblies

Switch '/microsoft.usage#ca2208" /ruleid' is an unknown switch.

Type 'FxCopCmd.exe /?' for help on command-line arguments.
MSBUILD : error : CA0059 : Invalid settings passed to CodeAnalysis task. See output window for details. 
Code Analysis Complete -- 1 error(s), 0 warning(s)

It looks like SonarQube isn't correctly generating the FxCop argument in this situation. 在这种情况下,SonarQube似乎无法正确生成FxCop参数。 Does anyone know a fix for this problem? 有人知道解决此问题的方法吗?

Thanks in advance. 提前致谢。

I've created a GitHub repro where this problem can be reproduced: https://github.com/mvdiemen/SonarQubeFxCopRoslyn 我创建了一个GitHub repro,可以在其中复制该问题: https : //github.com/mvdiemen/SonarQubeFxCopRoslyn

First of all, currently the Scanner for MSBuild does not support running FxCop through Roslyn. 首先,当前MSBuild扫描程序不支持通过Roslyn运行FxCop。 The reason is that it exposes rules that are intended to be used by FxCop in a specific way, different than other rules that are passed to Roslyn. 原因是它公开了打算由FxCop以特定方式使用的规则,这与传递给Roslyn的其他规则不同。

The analyzers that you are using, notably System.Runtime.Analyzers-1.2.0-beta2 , override the rule set for FxCop using the property CodeAnalysisRuleSetOverrides . 您正在使用的分析器(尤其是System.Runtime.Analyzers-1.2.0-beta2使用属性CodeAnalysisRuleSetOverrides覆盖FxCop的规则集。

MSBuild has the target CodeAnalysis which calls FxCopCmd.exe . MSBuild具有目标CodeAnalysis ,该目标调用FxCopCmd.exe As the CodeAnalysisRuleSetOverrides property is defined, FxCopCmd will receive as parameters all the rule IDs defined in that property. 定义CodeAnalysisRuleSetOverrides属性后, FxCopCmd将接收该属性中定义的所有规则ID作为参数。

The error you posted comes from a typo in the System.Runtime.Analyzers-1.2.0-beta2 analyzer when defining that property. 您发布的错误来自定义该属性时System.Runtime.Analyzers-1.2.0-beta2分析器中的错字。 There is a semicolon missing in packages\\System.Runtime.Analyzers-1.2.0-beta2\\build\\System.Runtime.Analyzers.props , which causes FxCopCmd.exe to fail. packages\\System.Runtime.Analyzers-1.2.0-beta2\\build\\System.Runtime.Analyzers.props缺少分号,这会导致FxCopCmd.exe失败。

Note that CodeAnalysisRuleSetOverrides overrides the rule set that is defined by the Scanner for MSBuild (through another property, CodeAnalysisRuleSet ). 请注意, CodeAnalysisRuleSetOverrides会覆盖由Scanner for MSBuild定义的规则集(通过另一个属性CodeAnalysisRuleSet )。 It is unintended because as a result FxCop will use the rules defined by the analyzers that you use in the project instead of the rules that are active in the Quality Profile defined in the SonarQube server. 这是意料之外的,因为结果是FxCop将使用您在项目中使用的分析器定义的规则,而不是SonarQube服务器中定义的Quality Profile中激活的规则。

I will fix the target file used by Scanner for MSBuild to reset the property CodeAnalysisRuleSetOverrides . 我将修复Scanner for MSBuild用来重置属性CodeAnalysisRuleSetOverridestarget文件。

To use the Scanner for MSBuild, you should remove those analyzers. 要将扫描仪用于MSBuild,应删除那些分析仪。 More information here: http://docs.sonarqube.org/display/SCAN/From+the+Command+Line 此处提供更多信息: http : //docs.sonarqube.org/display/SCAN/From+the+Command+Line

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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