'Clean up' whole c# solution based on editorconfig file

Viewed 31

I have a large C# solution for our actively worked on but old application. We have lots of files that have been around for years and lots of new files getting added all the time.

We have an editorconfig for the solution to enforce some code style rules and for new files and existing files we edit. That works fine but for existing files it introduces loads of formatting changes when maybe all you've 'really' changed is one line in the file.

So I'd like to 'clean up' the whole solution so that all files are 'correct' in one big change.

I've had a google around and I'm struggling to find anything about doing a big solution wide clean up.

Has anyone ever done something similar or any ideas on how to do it?

I have VS 2022 and Rider at my disposal.

Thanks

1 Answers

I'm not aware of a way to do it across all warnings/errors, but I've done it for each violation type by doing the following:

  1. Show the Error List.
  2. Double-click error of specific type, ex. IDE0055.

enter image description here

  1. Hover over squiggle to show the smart tag with "Show potential fixes". Screenshot shows shortcut CTRL+., but this does not work on my machine.

enter image description here

  1. Click "Show potential fixes" and select "Fix formatting in: Solution". This corrects thousands of violations across hundreds of files across multiple projects.

enter image description here

This works for me in a very large solution.

Related