Home

Quick Tip: Remove Unused References in Visual Studio

Technology
Quick Tip
Mark Arteaga
August 1, 2021

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!

Reset Filters
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

You may also like

Automated Testing Using Playwright

Technology
RedBit
Tony Wallace
March 27, 2023

How to create small viewport units in CSS

Technology
Design
Tony Wallace
January 9, 2023