Why Visual Studio reformatting .designer file?

test code 1 Reputation point
2023-04-01T11:41:53.42+00:00

I am using visual studio 2017 express, .designer.vb file is reformatting itself each time when I add new controls to form or when I build the solution? and sometime it simply changes the upper casing of True/False to true/false case!

Why Visual Studio reformatting .designer file?

Although it is reformatting, But I don't even understand in what order it is reformatting?

Is there any better ways to stop the visual studio from doing that?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,396 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,627 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,278 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,579 questions
{count} votes

2 answers

Sort by: Most helpful
  1. LesHay 7,126 Reputation points
    2023-04-01T14:37:31.1566667+00:00

    Hi

    The Designer file is built and maintained by the system and is not meant to be changed by the user (it can be edited as it is just a text file, but if you edit it, the system may overwrite your changes)

    The basic answer is: do not edit, view it to learn how to add some control code to your own code (i.e. how to add controls at run time).

    As for the formatting of the contents - that is entirely up to the system.

    with regard to your question: 'ways to stop the visual studio from doing that?' - not really is the answer, and, why bother even thinking about that, it is best to ignore that file and leave the system to handle it.

    Did you notice the

    	'NOTE: The following procedure is required by the Windows Form Designer
    	'It can be modified using the Windows Form Designer.  
    	'Do not modify it using the code editor.
    
    
    0 comments No comments

  2. Lex Li (Microsoft) 4,742 Reputation points Microsoft Employee
    2023-04-01T16:27:24.3533333+00:00

    What you observed has been there for two decades, due to the internal design of WinForms designer upon CodeDOM. Since CodeDOM was not smart enough to ignore default values and keep everything in order, it was recommended that you don't manually edit the file (because your edits might break CodeDOM and then you cannot easily get things back).

    It was only a few weeks ago that Microsoft rolled out a long due upgrade to WinForms designer (sadly only in VS 2022 for .NET Core/.NET based WinForms projects) that switches to Roslyn and you can read more about it in this post

    If you like, you can upgrade to VS 2022 Community edition and give it a try.

    0 comments No comments