Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove unused namespaces across a whole project or solution at once

Tags:

namespaces

c#

I know you can do it file by file.

Is there any way to do this in one step for all files in a project?

like image 449
leora Avatar asked Nov 12 '08 10:11

leora


People also ask

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!

How do I delete unused namespaces in Visual Studio 2019?

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

How do I delete all unused imports in Visual Studio?

Shift + Alt + O will take care of you.


1 Answers

There is no need for any plugins in VS 2017 or 2019. Click the bulb icon near any using statement and click Solution next to Fix all occurrences in part.

Screenshot of solution

like image 166
sotn Avatar answered Oct 13 '22 01:10

sotn