简体   繁体   English

FxCop和代码分析规则

[英]FxCop and Code Analysis Rules

I recently started using Code Analysis on my projects in Visual Studio. 我最近开始在Visual Studio中的项目中使用代码分析。 I have created a custom ruleset to use with all of my projects that include two of the Microsoft defined rulesets. 我创建了一个自定义规则集,用于包含两个Microsoft定义的规则集的所有项目。 I've been working to integrate FxCop into the CI build process to fail builds that don't pass all rules. 我一直在努力将FxCop集成到CI构建过程中,以使未通过所有规则的构建失败。 What's really odd to me is that I can't use my ruleset to define what rules FxCop scans the code against. 对我来说真正奇怪的是我不能使用我的规则集来定义FxCop扫描代码的规则。 How do I make it so Visual Studio's Code Analysis rules match up to FxCop's rules? 我如何使Visual Studio的代码分析规则符合FxCop的规则?

You already have a rule set file that I assume you have figured out how to integrate in your projects and utilize through Visual Studio. 您已经有了一个规则集文件,我假设您已经了解了如何集成到您的项目中并通过Visual Studio进行利用。

You can use this same rule set file in FxCopCmd.exe : 您可以在FxCopCmd.exe使用相同的规则集文件:

FxCopCmd.exe /out:Violations.xml /ruleset:=Custom.ruleset /file:MyAssembly.dll

I have done this using Jenkins and it works just fine. 我使用Jenkins做到了这一点并且工作得很好。 Run FxCopCmd.exe with no arguments and you should see descriptions for all available command-line switches. 运行FxCopCmd.exe带参数的FxCopCmd.exe ,您应该看到所有可用命令行开关的说明。

For our CI build we have a special build configuration (in addition to standard Debug and Release) which includes running code analysis ("RunCodeAnalysis" MSBuild task as i remember) and option "Treat warning as error". 对于我们的CI构建,我们有一个特殊的构建配置(除标准的Debug和Release之外),其中包括运行代码分析(我记得“RunCodeAnalysis”MSBuild任务)和选项“将警告视为错误”。 So the build fails if we have an FxCop error and it uses the same rule set as VS. 因此,如果我们有一个FxCop错误并且它使用与VS相同的规则集,则构建将失败。 This way you don't need to use FxCopCmd and can share rulesets. 这样您就不需要使用FxCopCmd并可以共享规则集。 But you have to manually add this build configuration to every project of your solution. 但您必须手动将此构建配置添加到解决方案的每个项目中。

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

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