In Visual Studio 2019 how can I remove unused usings on format document?
I have found instructions for previous versions of Visual Studio (Go to Tools > Options > Text Editor > C# > Code Style > Formatting.). I don't see that in Visual Studio 2019.
In Visual Studio 2019 how can I remove unused usings on format document?
I have found instructions for previous versions of Visual Studio (Go to Tools > Options > Text Editor > C# > Code Style > Formatting.). I don't see that in Visual Studio 2019.
In Visual Studio 2019 you can remove unused usings with the Code Cleanup command:
And running code cleanup also formats the document.
First : go Extensions - > install "Productivity Power tools" then "Power Commands for Visual Studio" extentsion
Second : go tools menu -> Options -> Productivity Power tools -> PowerCommands -> General -> checked "Remove and Sort Usings on save"
note : These options are available only when you use "Power Commands for Visual Studio".
The keyboard command that works for me is
I always use the combination CTRL + R, CTRL + G. This sorts the usings and removes the unused ones.
We can remove it by clicking on the light bulb and selecting" Remove Unnecessary Usings". In addition to removing it from the current document, if we closely look at the bottom of the popup, it can be done for the Project or Solution as well. No need to install or configure anything. This feature is available on VS2015, VS2017, VS2019 and VS2022 on my machine.
For single page :
Ctrl+K+E
For all projects:
You can assign both functions to Ctrl + K, Ctrl + D by changing hotkeys and keyboard shortcuts