MsbuildSonar Runner + Fxcop - 没有fxcop问题发布到server.SonarDashBoard显示0技术债务

时间:2015-10-20 14:52:10

标签: msbuild sonarqube sonar-runner

我正在使用Sonarqube 5.1和MsBuildSonarRunner进行c#.net项目分析。 Sonarqube 5.1附带了C#4.1插件,最近我升级到了4.2。我使用仅限Fxcop规则创建了质量配置文件。我已按照Sonar网站中提到的步骤进行分析。

在分析中,我看到捕获了FXcop规则违规。但当我浏览SonarDash董事会时,它显示技术债务为0并发出0。我已多次审查我的步骤,我没有看到任何错误。问题未发布到服务器的原因可能是什么。

这是我的Build命令日志。我清楚地看到FXCOP规则已应用,并且在构建阶段会在控制台上打印违规行为。

===========================================================

 Microsoft (R) Build Engine version 12.0.21005.1
[Microsoft .NET Framework, version 4.0.30319.34209]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 10/19/2015 12:20:14 PM.
Project "D:\Sqp\Polindrome\Polindrome\Polindrome.csproj" on node 1 (default targets).

GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.

CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.

_CopyAppConfigFile:
Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.

CopyFilesToOutputDirectory:
  Polindrome -> D:\Sqp\Polindrome\Polindrome\bin\Debug\Polindrome.exe

OverrideCodeAnalysisProperties:
  Running FxCop analysis using the SonarQube ruleset. Ruleset: D:\Sqp\Polindrome\Polindrome\.sonarqube\conf\\SonarQubeFxCop-cs.ruleset

RunCodeAnalysis:
  Running Code Analysis...
  C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe  /outputCulture:1033 /out:"bin\Debug\Polindrome.exe.CodeAnalysisLog.xml" /file:"bin\Debug\Polindrome.exe" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Xml.Linq.dll" /directory:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1" /ruleSet:"=D:\Sqp\Polindrome\Polindrome\.sonarqube\conf\\SonarQubeFxCop-cs.ruleset" /rulesetdirectory:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\\Rule Sets" /rule:"-C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop\\Rules" /searchgac /ignoreinvalidtargets /forceoutput /successfile /ignoregeneratedcode /saveMessagesToReport:Active /timeout:120 


MSBUILD : **warning CA1823: Microsoft.Performance : It appears that field 'Program.AccountList' is never used or is only ever assigned to. Use this field or remove it.** [D:\Sqp\Polindrome\Polindrome\Polindrome.csproj]

Code Analysis Complete -- 0 error(s), 1 warning(s)
SetStyleCopAnalysisSettings:
Setting 'sonar.stylecop.projectFilePath' to 'D:\Sqp\Polindrome\Polindrome\Polindrome.csproj'

WriteSonarQubeProjectData:
  Directory "D:\Sqp\Polindrome\Polindrome\.sonarqube\out\\Polindrome__AnyCPU_Debug_635803356164104589" doesn't exist. Skipping.
  Creating directory "D:\Sqp\Polindrome\Polindrome\.sonarqube\out\\Polindrome__AnyCPU_Debug_635803356164104589".
Done Building Project "D:\Sqp\Polindrome\Polindrome\Polindrome.csproj" (default targets).

Build succeeded.

"D:\Sqp\Polindrome\Polindrome\Polindrome.csproj" (default target) (1) ->
(RunCodeAnalysis target) -> 
  MSBUILD : warning CA1823: Microsoft.Performance : It appears that field 'Program.AccountList' is never used or is only ever assigned to. Use this field or remove it. [D:\Sqp\Polindrome\Polindrome\Polindrome.csproj]

    1 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.82

1 个答案:

答案 0 :(得分:0)

FxCop分析程序集,并依赖* .pdb文件将问题映射回源代码中的位置(即特定行的特定* .cs文件)。

CA1823报告的问题似乎是在一个字段上,由于* .pdb格式的限制而没有映射回源代码。在将FxCop结果导入SonarQube期间,将忽略这些问题。您可以通过手动打开FxCop报告(您将在.sonarqube \ out * \ ProjectInfo.xml中找到其路径)来验证该信息。

在C#插件的未来版本中已经有一张改进此功能的门票:https://jira.sonarsource.com/browse/SONARFXCOP-32

2015年11月18日更新

在对此答案进行了多次评论后(见下文),最终找到了问题的根本原因:SQL Server排序规则必须区分大小写(CS)和区分重音(AS)。

如果不是这样,SonarQube 5.3预计会更快失败,以避免出现这些奇怪的问题:https://jira.sonarsource.com/browse/SONAR-6884