How to enable Code Analysis in Visual Studio 2010 Professional?

佐手、 提交于 2019-12-20 09:13:07

问题


I can see that we can enable code analysis in Visual Studio Team Systems. But i am using 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.

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.


回答1:


You can integrate FxCop via Commandline in the post-build event of the solution.

Download FxCop 1.36 and add following command into the post-build event:

"$(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.

We have created a FxCop file that specifies the rules with FxCop-Gui. That file is loaded in the command.




回答2:


Check out this comparison chart, built-in code analysis support gets checked starting in the Premium column.




回答3:


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.Targets now).

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.




回答4:


You should enable Code Analysis manually. Follow the link here



来源:https://stackoverflow.com/questions/2833608/how-to-enable-code-analysis-in-visual-studio-2010-professional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!