Quick Tip - Remove Unused Using References in Visual Studio

August 1, 2021

Mark Arteaga

When working on a C# project be it Xamarin, ASP.NET Core etc within Visual Studio, developers sometimes forget to clean up using statements. Now Visual Studio does a good job of showing you visually unused using statements as follows

Example using statements in C# code

When you are working on bigger projects (in my current case, working on a project with 774 files), sometimes as a developer we forget to clean up our using statements as we go through code refactoring. Well, thanks to Visual Studio, we can quickly clean up `using statements` in a file in two ways

First is putting your cursor on one of the grayed out lines and clicking the light bulb, then clicking Remove Unnecessary Usings. (NOTE: The shortcut key for this is CTRL-.)

Visual Studio dialog to clean up using statements

When the action is executed the references will be cleaned up.

But what happens when you have 700+ files? Well if you noticed in the dialog, there is a section at the bottom that says

Fix all occurrences option

Here you can see the options are

  1. Document
  2. Project
  3. Solution

Now it's pretty obvious, what the options are, but in all my years of using Visual Studio, I have not noticed these options and no one wants to go through 700 files to clean them up! This is what the dialog looks like when you click `Solution`

Fix all occurrences dialog

So I don't know if this is a Visual Studio 2019 feature or if it's always been there. But this makes it a little more 'enjoyable' to go in and clean up lines of code that are no longer required in your source code!

Latest Posts

Be the first to know whats new at RedBit and in the industry. Plus zero spam.

Thank you! An email has been sent to confirm your subscription.
Oops! Something went wrong while submitting the form.

Let's Make Something Great Together

Contact Us