Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Visual Studio 2019 how can I remove unused usings on format document?

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.

like image 989
Anthony Avatar asked Apr 10 '19 14:04

Anthony


People also ask

How do I delete all unused imports in Visual Studio?

Shift + Alt + O will take care of you. If you're a heavy visual studio user, you can simply open your preference settings and add the following to your settings.

How do I delete unused namespaces in Visual Studio?

Go to Tools > Options > Text Editor > C# > Code Style > Formatting. It has an experimental Format Document Settings where you can have Visual Studio clean up your code. Two of the options are to "Remove unnecessary usings" and "Sort usings". Check these two and you're good to go!


2 Answers

In Visual Studio 2019 you can remove unused usings with the Code Cleanup command:

enter image description here

enter image description here

And running code cleanup also formats the document.

like image 74
Sergey Vlasov Avatar answered Oct 22 '22 00:10

Sergey Vlasov


CTRL + K + E Will sort and remove your unused usings.

like image 38
Jan Avatar answered Oct 21 '22 22:10

Jan