views:

59

answers:

1

The method definitions in any winform's *.Designer.cs file created 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 any one know why the attribute is not provided (it is generated code after all)? Would it be safe to add it myself (would it disappear when the code is re-generated, or does generation only occur within the method body)? If I were to add it, what would the proper tool and version strings be for Visual Studio 2010?

+2  A: 

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

That doesn't really help you solve your problem. The most effective fix I can think of is to simply edit the template. On my machine, that's c:\program files\microsoft visual studio 10.0\common7\ide\itemtemplatescache\csharp\windows forms\1033\form.zip\form.designer.cs, put the attribute before the method. What you use doesn't really matter, no tool is going to expect this attribute to be there.

Hans Passant
Thanks! I like the idea of modifying the template; I'll use the template name as the tool name.
Timothy