Clean Up & Sort Unused .NET Using Statements in Visual Studio

I needed to do a refactor that broke a namespace into multiple namespaces. Their may be some other way to do this in Visual Studio. The easiest way I thought of was finding & replacing the old namespace with the new namespaces. This meant I would be adding namespaces to files they weren't used in. Not a big deal, but something I prefer to avoid.

Fortunately for me, Visual Studio added a sweet new clean up feature in version 15.8. It even works on the free Community version.

Format Document Settings Window

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! No need for an extension or ReSharper to do this anymore.

Matt Ferderer

Full Stack Software Developer focused on JavaScript and C#. Love to share & help others make amazing things. Have a project you need help on? Let's talk!

comment

Comments