Search code examples
visual-studio-2022

How to stop annoying feature to remove using statements on save in Visual Studio 2022?


I cannot find any setting to stop this madness, any suggestions?

All the unused using statements are removed when saving, not so great when converting a bunch of projects and manually updating multiple files.


Solution

  • It sounds like you have Code Cleanup configured to run on Save. You can configure this it Tools -> Options -> Text Editor -> Code Cleanup.

    Tools/Options configuration for Code Cleanup

    Alternatively, you can configure which tasks Code Cleanup performs and set it to not remove the using statements. You can find this under Analyze -> Code Cleanup -> Configure Code Cleanup, or on the lower editor margin in a button with a sparkling broom symbol.

    Configure Code Cleanup dialog