Option to Turn off Designer Code Formatting #8754
-
My coding format uses tabs for aligning various kinds of statements like assignments, breaks, error propagation and more. There are no formatting settings that achieve this kind of format so I have to resort to turning off all formatting that I can. Unfortunately both Winforms and Dataset designers do not have an option to turn of auto formatting. Now, in VS 17.5, even "code behind" files get reformatted. Immediately after a form is opened in the designer! This is a total stop for me so I am moving back to 17.4. There is over a million lines of code that I have written that need to not be re-formatted: I have tabbed and organized it as I need it to be. Can we please have a setting for turning off auto formatting? I would like to turn it off everywhere if possible. It seems like it should be a simple options to implement. |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 7 replies
-
The *.Designer.cs file is auto-generated, and it has a note at the top of the file to that effect. |
Beta Was this translation helpful? Give feedback.
-
@AssisiSoft, what do you mean by partial classes associated with designer but are not auto generated? Can you attach a simple application here for reference? |
Beta Was this translation helpful? Give feedback.
-
Below is a class EditorMap, defined in two files: my code in EditorMap.cs and Winforms designer code in EditorMap.designer.cs. In versions of VS prior to 17.5, the winforms designer would reformat its designer code in “EditorMap.designer.cs” but leave my code in “EditorMap.cs” alone. Version 17.5 reformats both files now. We need an option to turn off auto format at least for our edited code. Preferably for all files if desired.
EditorMap.cs…
internal partial class EditorMap : Editor
{
//My Code in my own preferred format please!
//Do not autoformat this code. The Designer is not writing it, I am.
}
EditorMap.designer.cs…
internal partial class EditorMap : Editor
{
//Designer code in designer’s format.
}
Rich Howard
Assisi Software
503.233.6417
***@***.******@***.***>
www.AssisiSoft.com<http://www.assisisoft.com/>
***@***.***
Online Resources
User Forum<http://www.assisisoft.com/forum>
Library<http://www.assisisoft.com/library>
Version History<http://www.assisisoft.com/versionhistory>
From: Devendar Reddy Adulla ***@***.***>
Sent: Monday, March 13, 2023 2:55 PM
To: dotnet/winforms ***@***.***>
Cc: Rich Howard ***@***.***>; Mention ***@***.***>
Subject: Re: [dotnet/winforms] Option to Turn off Designer Code Formatting (Discussion #8754)
@AssisiSoft<https://github.com/AssisiSoft>, what do you mean by partial classes associated with designer but are not auto generated? Can you attach a simple application here for reference?
—
Reply to this email directly, view it on GitHub<#8754 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AWOUJOECLAB4CNMYVVBZENTW36JUJANCNFSM6AAAAAAVRZQO7A>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Yes, that's a known issue and should be on our internal Designer to do list. @Olina-Zhang: Can you create a quick repo, where you add code to Form1.cs which is "custom formatted", and we show, that the code gets formatted after writing it. @Tanya-Solyanik, @merriemcgaw, FYI. As an (internal) suggestion: We could opt out of formatting for C# for code-files which don't contain |
Beta Was this translation helpful? Give feedback.
-
@KlausLoeffelmann It is a similar issue in our internal designer repo: https://github.com/microsoft/winforms-designer/issues/5079 |
Beta Was this translation helpful? Give feedback.
-
This isn't just a minor blip. It is a huge f**ing problem!!! I use Resharper for all my formatting and I thought I was going mad reformatting the same bit of code. I then had the Form side by side with the code, made a trivial change on the Form and changed it back and clicked Save in the toolbar. I hope the OP is right and going to v17.4 will get around the problem. |
Beta Was this translation helpful? Give feedback.
-
We will be addressing this in 17.7 and are discussing servicing it back for 17.6. |
Beta Was this translation helpful? Give feedback.
-
The Designer needs to write to other files in these cases:
|
Beta Was this translation helpful? Give feedback.
-
The new serialization logic works with forms where InitializeComponent is written to Form1.cs file.
This is a great suggestion. I think we could create an analyzer that splits out InitializeComponent into the .Designer file. @merriemcgaw - how do we handle suggestions like this? |
Beta Was this translation helpful? Give feedback.
-
I agree - we should have an Analyzer and a Code Fixer for this! To clarify: The change I am currently working on (amongst other things, btw) will limit formatting only to the spots which have actually changed. But everything inside of |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, the changes where too extensive to integrate into 17.7 that late in the release cycle. The change made it to 17.8 Preview 1, though. We will continue to watch for customer feedback, and may decide at a later date, if we want to service 17.6 with the change, since 17.6 is LTS. |
Beta Was this translation helpful? Give feedback.
-
Woo Hoo!
Unfortunately, the changes where too extensive to integrate into 17.7 that late in the release cycle. The change made it to 17.8 Preview 1, though. We will continue to watch for customer feedback, and may decide at a later date, if we want to service 17.6 with the change, since 17.6 is LTS.
|
Beta Was this translation helpful? Give feedback.
-
Can you please file a bug for this, since it's a different issue? |
Beta Was this translation helpful? Give feedback.
Yes, that's a known issue and should be on our internal Designer to do list.
@Olina-Zhang: Can you create a quick repo, where you add code to Form1.cs which is "custom formatted", and we show, that the code gets formatted after writing it. @Tanya-Solyanik, @merriemcgaw, FYI.
As an (internal) suggestion: We could opt out of formatting for C# for code-files which don't contain
InitializeComponent
, because we never touch them to begin with. We should for the time being continue doing this for VB, since we're touching the code when we're updating the event handler method stubs.