Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid unnecessary changes in *.designer.cs and *.resx?

Tags:

For some reason Visual Studio winforms designer time to time applies dull changes to form designer files and respective resx.

Most annoying so far:

  • changes to order of controls declarations/initialization
  • changes to some control sizes (most notably menu items widths)
  • changes to serialized images embedded into resources (...wait, what???)

Those changes doesn't affect form/user control functionality or it look, but they create lot of noise in source control, making merges almost impossible, or require error prone manual fixing to eliminate all changes that actually change noting, just until next change to designer.

Any ideas how to prevent studio from it?

like image 420
Andriy K Avatar asked Jul 08 '14 16:07

Andriy K


People also ask

What is resources designer cs file?

This class is contained in the Resources. Designer. cs file which is nested under the Resources. resx file in Solution Explorer. The Resources class encapsulates all your project resources into static readonly get properties as a way of providing strongly-typed resources at run-time.

How do I generate designer CS from Resx?

Right click the resx-file and select properties. Add the value "PublicResXFileCodeGenerator" to the "Custom Tool" property then the designer file will be generated.


1 Answers

Please try to have your control locked using the right button, then select "Lock controls" on your Form/UserControl.

enter image description here

Unfortunately, there is no way to separate "useful" changes in generated code from "pollution" that come from a control designer bug or internal working.

If the lock control feature does not work for whatever reasons, there is not much that we can do, except those horrible hacks:

  • Once your form is created and finished, move your generated code (InitializeComponent method and declarations) out of the .designer.cs. Visual Studio will not touch it anymore. The drawback is that you will no longer have visual support.

  • Having the .designer.cs file flagged as read only will prevent Visual Studio attempting to change it. It might cause Visual Studio control designer hiccups sometimes, but it will leave your .designer.cs intact.

There is another way that consist in not using the designer at all. This leads to a new way to embrace winforms programming, because you will provide the code to initialize controls with their properties and events.

It is not as huge and ugly as it seems to be: using reusable patterns and OO features could be very pleasant, and some well aligned methods calls are better that some horrible code hidden in a .designer.cs file.

Of course there will be no visual support, but you can cheat it by adding your control to an empty container in design mode to see how it looks like.

like image 165
Larry Avatar answered Sep 22 '22 21:09

Larry