Attribute missing from generated WinForm code

Method definitions in any winform * .Designer.cs file generated by Visual Studio are not decorated with [GeneratedCodeAttribute] attributes. As a result, the generated code is analyzed when I run code metrics or code analysis. Does anyone know why the attribute is not provided (it is generated by the code after all)? Would it be safe to add it yourself (will it disappear when the code is generated or only generated inside the body of the method)? If I had to add it, what would be the correct tool and version strings for Visual Studio 2010?

+2


a source to share


1 answer


Well, it's tricky, it's not actually auto-generated code. The Designer.cs file is generated by the project item template. The Windows Forms design-time serializer restores only the body of the InitializeComponent () method and adds control declarations to the bottom of the file.



It will not help you solve your problem. The most efficient fix I can think of is to simply edit the template. On my machine, to compile the attribute before this method, do the following: c: \ program files \ microsoft visual studio 10.0 \ common7 \ ide \ itemtemplatescache \ csharp \ windows forms \ 1033 \ form.zip \ form.designer.cs. What you use doesn't really matter, no tool expects this attribute to be there.

+4


a source







All Articles