Why does Visual Studio rearrange the .designer files all the time?
Asked Answered
F

1

9

You usually don't see those files because they're hidden in the project tree and you only edit the GUI of a Windows Forms .NET application through the visual designer. But when using some kind of SCM (version control), it's a huge PITA when those files change significantly all the time. Even when I don't touch a single thing in the designer and just rebuild the solution or even open it in VS, many lines of code are moved to another position in the file. This always makes a hugh change set that nobody can explain or even analyse.

Is there a way to stop Visual Studio from doing that? I've seen it in every version up to 2010. I think WPF XAML files should not be affected by this, but WPF is not an option here.

Febri answered 14/12, 2011 at 10:58 Comment(4)
I would love to see an answer to this.Afroamerican
You are saying that when you just open solution in VS or building it - your *.Designer.cs files are changing? I mean - you don' open forms in VS Designer and they still changing?Headrick
This seems to happens to me as well, and as a side note, I'm using Visual Studio 2012 Ultimate (the question mentions only up to 2010). I noticed it when looking through my git history.Mabellemable
Its now 2020, VS 2019 still does the same. Enough to open a form in a VB.NET project which is under source control, VS will check it out, when saved (for example you change the code behind it but not the layout) its the same logical content in the .resx and .designer.vb files but most lines rearranged. Makes no sense.Friedlander
S
0

The designer builds an internal object model of the form/control. When a change is made to this object model, the code is regenerated.

Silverside answered 3/9, 2015 at 13:10 Comment(1)
The code is regenerated every time you open the form, and its regenerated diferentently for no reason. The logical content remains the same, the order of lines not relying on each other is altered. For example, doesnt matter if you set background color first or foreground color. Yet the forms designer may change their order for no reason at all.Friedlander

© 2022 - 2024 — McMap. All rights reserved.