Reputation: 1837
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.
Upvotes: 62
Views: 52575
Reputation: 3240
For single page :
Ctrl+K+E
For all projects:
Right click to your solution on your Solution.
Click on Analyze and Code Cleanup followed by Run Code Cleanup (Profile 1)
And all done, it cleans and formats all over the project.
If you need some more setting on code cleanup or if it don't work you need to click on configure code cleanup below cleanup profile.
Upvotes: 11
Reputation: 1365
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.
Upvotes: 8
Reputation: 389
I always use the combination CTRL + R, CTRL + G. This sorts the usings and removes the unused ones.
Upvotes: 6
Reputation: 161
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".
Upvotes: 16
Reputation: 776
There is no need to call it by hand, you can use 'cleanup on save' see this post
Upvotes: 0
Reputation: 81
You can assign both functions to Ctrl + K, Ctrl + D by changing hotkeys and keyboard shortcuts
Upvotes: 0
Reputation: 27920
In Visual Studio 2019 you can remove unused usings with the Code Cleanup command:
And running code cleanup also formats the document.
Upvotes: 68