Share via

Why Visual Studio reformatting .designer file?

test code 21 Reputation points
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?

Developer technologies | .NET | Other
Developer technologies | VB
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.

Developer technologies | C#
Developer technologies | 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.


2 answers

Sort by: Most helpful
  1. Lex Li 6,042 Reputation points
    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.

    Was this answer helpful?

    0 comments No comments

  2. LesHay 7,146 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.
    
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.