开发者

Force WinForms to regenerate .designer.cs files

We have a controls 开发者_StackOverflow社区project that contains many controls used throughout our applications. There are many old and many redundant properties on these controls, and almost none of them have attributes specified on them (such as DefaultValue() in particular).

As part of the effort to clean them up, we have added attributes to the properties, and are looking to remove the redundant ones.

What we would like to do as part of this is to clean the generated code from the winforms designer (the xxxxxx.designer.cs and xxxxxx.designer.vb files). Some of the properties are straight removal, for which we were able to use Grep and Sed to remove the offending lines, but we are looking for a way to make Visual Studio (or something) to regenerate the files.

As we have 100's of forms, it is infeasible to manually open each one and modify them to do this.

Does anyone know of a way to do this?

Edit:

To clarify, what I mean is not to remove the properties straight away, but to apply the DesignerSerializationVisibity() attribute to them to tell the designer to not write them. Then once we have updated all the designer files, we can delete the properties.

See Also:

Automatic regenerate designer files


Not possible, you can't get the designer to parse InitializeComponent() when it contains property assignments for properties that you have removed or renamed. It has to parse it before it can regenerate the code.

The only real approach is to first apply the [DesignerSerializationVisibility] attribute to the old property so it no longer writes the property assignment. Then load each form and make a trivial edit to get it to regenerate InitializeComponent(), now without the property assignment. Then you can remove them. Directly editing the method could be quicker.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜