如何抑制生成的代码代码分析? [英] How to suppress code analysis on generated code?

查看:233
本文介绍了如何抑制生成的代码代码分析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成Reference.cs Silverlight项目文件所在的服务引用是。类是由于与[GeneratedCode],并在项目配置上生成的代码的代码分析被禁用(发布和调试)。

I have a Silverlight project with a generated Reference.cs file where the service reference is in. The class is attributed with [GeneratedCode] and in the project configuration the code analysis on generated code is disabled (Release and Debug).

我做了什么错?

推荐答案

也许你应该尝试对于工作StyleCop的解决方案:

Maybe you should try the solutions that works for StyleCop:

1)把了.Designer.cs给你不想要了StyleCop检查文件名的末尾。或致电类,以及包含它,NativeMethods的文件。请确保您还取消选中分析设计文件中了StyleCop设置。在这种情况下,整个文件将被旁路。你不必为某些类型的微软设计器生成的代码,如Windows窗体设计这样做,是因为他们下列选项的情况下自动掉落:

1) Put ".Designer.cs" to the end of the name of the file you don’t want StyleCop to check. Or call the the class, and the file containing it, "NativeMethods". Make sure you also uncheck "Analyze designer files" in StyleCop settings. In this case the whole file will be bypassed. You don’t have to do so for some types of Microsoft designer-generated code, like Windows Forms Designer, because they automatically fall under conditions of the following option:

2 )环绕不需要的一段代码中含生成的代码在其名称中一个C#的区域。了StyleCop默认情况下不检查生成的代码(确保分析生成的文件设置未选中,虽然)。在这种情况下,你仍然可以验证的Windows窗体控件生成的字段的名称。

2) Surround the undesired piece of code with a C# region containing "generated code" in its name. StyleCop does not check generated code by default (make sure the "Analyze generated files" setting is not checked, though). In this case you can still validate the names of the fields generated for the Windows Forms controls.

#region Windows窗体设计器生成的代码

...

#endregion

3)要忽略整个生成的文件,请检查您是否生成一个提出XML元素成对了StyleCop,符合文件头,如下所示:

3) To ignore the whole generated file, check whether your generator puts an "" XML element into the StyleCop-conform file header, like the following:

//<自动生成/>

4)最后,你可以设置为表示需要从分析中排除该文件的MSBuild编译项目真ExcludeFromSourceAnalysis属性。它只有在使用所提供的Microsoft.SourceAnalysis.Targets目标文件,否则你有你自己想要的源文件养活了StyleCop MSBuild任务的工作。

4) And finally, you can set to true the "ExcludeFromSourceAnalysis" property of the MSBuild Compile item that represents the file needed to be excluded from analysis. It only works if you use the provided "Microsoft.SourceAnalysis.Targets" targets file, otherwise you have to feed the StyleCop MSBuild task with desired source files on your own.

来源: http://shishkin.wordpress.com/2008/07 / 08 /了StyleCop,如何对忽略生成码/

这篇关于如何抑制生成的代码代码分析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆