How to suppress code analysis on generated code?

喜欢而已 提交于 2019-11-29 18:14:07

问题


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

What have I done wrong?


回答1:


Maybe you should try the solutions that works for StyleCop:

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) 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 Form Designer generated code

...

#endregion

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

// <auto-generated />

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.

Source: http://shishkin.wordpress.com/2008/07/08/stylecop-how-to-ignore-generated-code/



来源:https://stackoverflow.com/questions/4164928/how-to-suppress-code-analysis-on-generated-code

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