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

1

6

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.

Nonconductor answered 28/1, 2022 at 18:42 Comment(0)
M
13

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

Macro answered 29/1, 2022 at 9:3 Comment(2)
But it does not remove unused propertiesUtmost
@Utmost It does not by default, but it can be configured to remove unused references.Nonconductor

© 2022 - 2024 — McMap. All rights reserved.