Excluding Code Analysis rule in source

房东的猫 提交于 2019-11-30 08:11:31

You've probably got the right code, but you also need to add CODE_ANALYSIS as a precompiler defined symbol in the project properties. I think those SuppressMessage attributes are only left in the compiled binaries if CODE_ANALYSIS is defined.

In FxCop 1.36 there is actually a project option on the "Spelling & Analysis" tab that will supress analysis for any generated code.

If you don't want to turn analysis off for all generated code, you need to make sure that you add a CODE_ANALYSIS symbol to the list of conditional compilation symbols (project properties, Build tab). Without this symbol defined, the SupressMessage attributes will be removed from the compiled code so FxCop won't see them.

The other problem with your SuppressMessage attribute is that you are listing a "Target" of a specific method name (in this case WindowsClient.MainForm.InitializeComponent():System.Void) and listing a specific "Scope". You may want to try removing these; otherwise you should add this SuppressMessage to each instance of the method.

You should also upgrade to the RTM version of FxCop 1.36, the beta will not automatically detect the newer version.

Module level suppression messages need to be pasted into the same file as the code that is raising the FxCop error before the namespace declaration or in assemblyinfo.cs. Additionally, you will need to have CODE_ANALYSIS defined as a conditional compiler symbols (Project > Properties > Build). Once that is in place, do a complete rebuild of project and the next time you run FxCop the error should be moved to the "Excluded in Source" tab.

Also, one small tip, but if you are dealing with a lot of FxCop exclusions it might be useful to wrap a region around them so you can get them out of the way.

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