2013-10-25 151 views
0

我正在尝试在我的持续集成系统中配置静态代码分析(FxCop)。但我的开发人员正在使用规则集文件进行Visual Studio静态分析。如何将规则集文件转换为FXCop规则dll?

有没有办法让我可以重复使用相同的规则集文件,并将其转换为FxCop规则集的dll,并执行静态代码分析,同时构建?

由于提前, 拉维

+0

你是如何在构建服务器上触发FxCop的? –

回答

1

如果您安装了CI服务器上的Visual Studio,则只需将的MSBuild命令行上指定/p:RunCodeAnalysis=[True|False|Always|Default|Never]应该运行代码分析,因为它是对开发商的配置设置。规则文件自动包含在Visual Studio项目文件中,因此它们应该自行解决。

要在生成后运行的FxCop您可以指定规则集作为命令行参数:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop>fxcopcmd /? 
Microsoft (R) FxCop Command-Line Tool, Version 12.0 (12.0.21005.1) X86 
Copyright (C) Microsoft Corporation, All Rights Reserved. 

/ruleset:<<+|-|=>file> [Short form: /rs:<<+|-|=>file>] 
Rule set to be used for the analysis. It can be a file path to the rule set 
file or the file name of a built-in rule set. '+' enables all rules in the 
rule set; '-' disables all rules in the rule set; '=' sets rules to match the 
rule set and disables all rules that are not enabled in the rule set. 

/rulesetdirectory:<directory> [Short form: /rsd:<directory>] 
Directory to search for rule set files that are specified by the /ruleset 
switch or are included by one of the specified rule sets. 

从命令行运行的FxCop的困难的部分是,你将要传递的所有引用,它只能处理相同.NET系统库的文件(它只能保存内存中的一个)。使用以下参数可以指定这些引用:

/platform:<directory> [Short form: /plat:<directory>] 
Location of platform assemblies. 

/directory:<directory> [Short form: /d:<directory>] 
Location to search for assembly dependencies. 

/reference:<file> [Short form: /ref:<file>] 
Reference assemblies required for analysis. 
+0

这似乎是一个很好的解决方案,如果我想运行代码分析作为Build.But的一部分,在我的情况下,运行代码分析作为后期构建脚本。是否有任何方式来设置扩展设计指南,同时运行FxCopCmd由Visual Studio代码分析提供的工具? – Ravi

+0

是的,你可以更新答案 – jessehouwing

0

如果你想运行代码分析只,而无需直接调用的FxCop并指定所有这些额外的信息,请执行以下操作:

<MSBuild Projects="@(CodeAnalysisProjects)" Properties="RunCodeAnalysis=True;Configuration=Release;BuildProjectReferences=False;WarningsAsErrors=False;RunCodeAnalysisDependsOn=;" Targets="RunCodeAnalysis" StopOnFirstFailure="false" /> 

你发送项目组中的项目列表CodeAnalysisProjects.您运行目标RunCodeAnalysis,并设置属性RunCodeAnalysis=True.您还可以设置属性RunCodeAnalysisDependsOn=;,以便除代码分析外别无其他。

这是我们用于CI的相同解决方案。我们整天构建,然后只在晚上运行代码分析。