Visual Studio: Remove Unused References and Assemblies from your Project

When you create a default project in Visual Studio, there are a couple of references and assemblies that get added by default. Just create any new Window, Web, Console or Silverlight project using Visual Studio and check the using directives (only in C# templates) as well as the assemblies that get added.

Visual Studio Usings

You may not need them all. So after you have finished coding, it’s a good idea to remove unused references as well as assemblies from your project to improve code readability, maintainability as well as gain a slight advantage in the applications load time. If you are using a C# code template (VS 2008 and 2010), you can do the following:

Right-click in your Code behind file > Organize Usings > Remove Unused Usings

Remove Unused Usings

You will find that all unnecessary using directives have been removed. Internally Visual Studio scans through the code and determines the using statements that are necessary for the code to compile. It then removes all other Using statements not needed by the project. After clicking on the ‘Remove Unused Usings’ in the image shown above, here’s what’s left

Remove Unused Usings

Similarly if you are using a VB template, you can use the References Property page to remove unused references from the project. To do so, right click the VB project > Properties or use shortcut Alt+Enter. Select the ‘References’ tab and click on the ‘Unused References’ button.

Unused References

Clicking the button queries the project to determine the references that are not used by the project

Remove Unused References

Click on the Remove button to remove the references not needed.

Note: If you are wondering why is the Remove Unused Assembly feature in a VB template and not in a C# template, read this Bug on MS Connect. Till this gets fixed, NDepend could prove useful,

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.


Muse VSExtensions said...

If you are using C#, Muse VSExtension will remove unused references for you

fOr more details visit:

Anonymous said...

See this post

Very helpfull addin

Anonymous said...

> See this post
> Very helpfull addin

Thanks a lot! Nice tool!

Pete said...

Nice article. Just wondering any benefit by removing unused references?