Search code examples
visual-studiovisual-studio-2022automated-refactoring

Is there an option to remove unused references on save in Visual Studio 2022?


Is there an option to remove and sort usings automatically on save for the current document? This used to be provided by the Power Commands for Visual Studio extension. Is this available somewhere in the Visual Studio 2022 options? Or is provided by some other extension?

I tried searching in the Tools>Options. And also searched the web for a while, but could not find a solution.


Solution

  • This can be done with the Code Cleanup feature. Starting in 17.1 Preview 2, this can be triggered on save. See the announcement at https://devblogs.microsoft.com/visualstudio/bringing-code-cleanup-on-save-to-visual-studio-2022-17-1-preview-2/

    On versions prior to that, there is an extension that works with either VS2019 or VS2022 called Code Cleanup On Save