
Bingo! Thanks David, I'll admit that I have neglected the Code Cleanup feature and it went out of my mind. I have fiddled with it occasionally over the years but I couldn't get it to work the way I wanted. But this time I concentrated and: • Set all the Tools Options C# preferences I want (takes time). • Saved the .editorconfig file in the solution folder. • Configure Code Cleanup -- *It's hard to know which Available fixers to include, because you don't know which specific preferences are inside each fixer. I noticed that using statements weren't being moved to the outside and I wasn't getting file-scoped namespaces, so I had to scroll down the Available list and guess which ones to include. I noticed I needed an experimental one to remove excess blank lines.* • Run the cleanup. *I accidentally clicked the main window while the cleanup was running and it went grey and asked if I wanted to wait for the app to respond, which it eventually did, but the progress dialog was hidden and only visible by holding Alt+Tab.* So overall, after you take time to get everything just right, it works like a dream. It's hard to know how the .editorconfig file and the VS options are affecting the process or if they are fighting each other. Maybe the file takes preference outside VS when using the dotnet format command (which I haven't tried yet). I'd love an option to remove blank lines immediately inside method opening and closing braces so you don't get this: void Something() { WriteLine("I hate the blank lines around this"); } *Greg K* On Wed, 12 Apr 2023 at 11:18, David Kean <David.Kean@microsoft.com> wrote:
Both of these options can do this on a per solution, project, document basis.
If you want to this via command-line, look at *dotnet format*. These all work better if you’ve got a good .editorconfig that calls the style <https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-sty...>. You can have IntelliCode automatically generate one based on the project via Add -> New Item -> Editor Config (IntelliCode).
*From:* Greg Keogh via ozdotnet ozdotnet@ozdotnet.com *Sent:* Wednesday, April 12, 2023 11:03 AM *To:* ozDotNet <ozdotnet@ozdotnet.com> *Cc:* Greg Keogh <gfkeogh@gmail.com> *Subject:* VS2022 format all files
Folks, is there a way to apply commands like *Format Document* and *Remove and Sort Usings* to multiple C# files, perhaps all open files or all files in the project?
Web searches suggest it's not possible at the moment. I see an Extension for this which looks a bit flakey and I won't try it yet.
Taking this even further, I occasionally need to "beautify" C# code in hundreds of files in projects to fix things like indentation, tabs, usings and more fiddly things like removing excess blank lines, putting gaps between methods, etc. That is, I want to bring code that is sometimes haphazardly formatted back to a vanilla format acceptable to typical developers.
Cheers,
*Greg Keogh*