visual-studio 如何在 Visual Studio 2010 Professional 中启用代码分析?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2833608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to enable Code Analysis in Visual Studio 2010 Professional?
提问by kiran826
I can see that we can enable code analysis in Visual Studio Team Systems. But i am using Visual Studio 2010 Professional.
我可以看到我们可以在 Visual Studio Team Systems 中启用代码分析。但我使用的是 Visual Studio 2010 Professional。
Do we have any option to enable code analysis in this version or can we integrate any tools like FxCop and StyleCop with this version for validating the code.
我们是否可以选择在此版本中启用代码分析,或者我们是否可以将 FxCop 和 StyleCop 等任何工具与此版本集成以验证代码。
I am expecting my code should analysied the moment i build my solution.
我期待我的代码应该在我构建解决方案的那一刻进行分析。
If somebody aware of this, please share me some solution for this.
如果有人知道这一点,请与我分享一些解决方案。
回答by Chris U
You can integrate FxCop via Commandline in the post-build event of the solution.
您可以在解决方案的构建后事件中通过命令行集成 FxCop。
Download FxCop 1.36 and add following command into the post-build event:
下载 FxCop 1.36 并将以下命令添加到构建后事件中:
"$(ProgramFiles)\Microsoft FxCop 1.36\FxCopCmd.exe" /c /p:"$(ProjectDir)\FxCop$(ConfigurationName).FxCop" /consolexsl:"$(ProgramFiles)\Microsoft FxCop 1.36\Xml\VSConsoleOutput.xsl"
Via consolexsl parameter the output is formatted so that the output is included into you VisualStudio builderrors and -warnings.
通过 consolexsl 参数,输出被格式化,以便输出包含在你的 VisualStudio builderrors 和 -warnings 中。
We have created a FxCop file that specifies the rules with FxCop-Gui. That file is loaded in the command.
我们已经创建了一个 FxCop 文件,它指定了 FxCop-Gui 的规则。该文件在命令中加载。
回答by Andriy K
There was also StyleCop mentioned in the original question, let me answer that part: it can be integrated into build chain too as described in this article. Sure you have to adjust path and target mentioned in article with current path/version of StyleCop (it's $(ProgramFiles)MSBuild\StyleCop\v4.7\StyleCop.Targetsnow).
原问题中也提到了StyleCop,我来回答一下:它也可以像这篇文章中描述的那样集成到构建链中。当然,您必须使用 StyleCop 的当前路径/版本($(ProgramFiles)MSBuild\StyleCop\v4.7\StyleCop.Targets现在)调整文章中提到的路径和目标。
To make it work out of box (source control), I usually copy targets file, StyleCop binaries into some folder in SC (target file can be adjusted for that), and use relative paths to reference it. This allows to avoid creating any environmental variables, and project can be build immediately from SC on blank machine.
为了使其开箱即用(源代码控制),我通常将目标文件、StyleCop 二进制文件复制到 SC 中的某个文件夹中(可以为此调整目标文件),并使用相对路径来引用它。这可以避免创建任何环境变量,并且可以在空白机器上从 SC 立即构建项目。
回答by Hans Passant
Check out this comparison chart, built-in code analysis support gets checked starting in the Premium column.
查看此比较图表,从 Premium 列开始检查内置代码分析支持。

