Quantcast
Channel: Raju RH
Viewing all articles
Browse latest Browse all 25

Tidy up - Unused Project and Nuget package reference using Visual Studio 2019

$
0
0

If you are a Developer/Architect using Visual Studio as IDE for your development activities, this blog post will be of your interest. During the Ignite 2021 conference, Microsoft released Visual Studio 2019 v16.9 and v16.10 Preview 1. As part of version 16.10 Preview 1, one of the cool features they introduced is to "Remove Unused References..." for any Projects and Nuget packages that are not in use. At the time of writing this blog post, we have Visual Studio Version 16.10.0 (official release) which includes this new feature. 

As part of development, we generally get carried away and introduce new Nuget package references to your project and add new references to your Projects. By the end of development, you will not be 100% sure which are not being referenced and unused which means you will leave those unused project references in your application. Now you might be wondering what's the big deal in it since it doesn't harm. The advantage of removing unused project references and Nuget packages will not only keep your solution clean but also helps to save space and reduce the startup time of your application. Also if you're not removing unused references then the compiler loads metadata that will never be used. In summary, it's always a good practice to tidy up projects and Nuget package which are not in use.

Let's look in action at how we can leverage this feature in Visual Studio 2019. 

Pre-requisites: Visual Studio Version 16.10.0 (official release) and any existing .NET project.

  • I have a small console application in which have added a couple of Nuget packages like Serilog, Azure Storage DataLake which are not been referenced in the application code. Additionally have added a library project within the solution and referenced it in the console application with no code reference usage.
Project Structure with references
  •  Now let's navigate to Solution Explorer and right-click on the project which we need to analyze for "Unused project and Nuget package references" 
Option for "Remove Unused References..."
  • Once we click on "Remove Unused References..." it pops with a dialog of unused packages and project references with the option to "Remove" or "Keep" as shown below. If there are no unused project references then it shows "No unused references were found".
Analyzed Results
  • Once you click on "Apply" you will be presented with the below window and clicking on "Yes" unused project references will be removed.
Removed unused project and package references




Viewing all articles
Browse latest Browse all 25

Latest Images

Trending Articles





Latest Images