简体   繁体   中英

What things trigger Visual Studio to regenerate a *.Designer.cs file?

Some form initialization issues I was having were traced to the .Designer.cs file overwriting values I had initialized in a user control's constructor.

I had designed a component ( MyUserControl ) and inserted it into a form ( MainForm ). I later added some member initializations in MyUserControl 's constructor, but the code that was in MainForm.Designer.cs for InitializeComponent() was stale, and code later in that functions was overwriting the my new initializations from the constructor called earlier in that function.

So, in essence, something I did triggered a rewrite of Mainform.Designer.cs but other activities didn't.

Is there a good reference that describes when the designer touches the *.Designer.cs files? (Or is it a simple rule?) Jared Par pointed me to the DesignerSerializationVisibilityAttribute class but that seems to be one tree in the forest?

You specifically fell victim to having code for the old version of your UserControl still embedded in the form's InitializeComponent() method. If you would have removed the control from the form before modifying the control code then you wouldn't have had the problem. Removing it afterwards and putting it back would have fixed it too.

Yes, it is a simple rule. InitializeComponent() is re-generated every time you add or remove a control to/from the form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM