I want to know if any tool exists for removing unused references (not unused using
directives) within a .NET C# project.
-
duplicate of http://stackoverflow.com/questions/81597/remove-unused-references-using – Agent_9191 Nov 24 '09 at 08:39
-
Possible Duplicate http://stackoverflow.com/questions/81597/remove-unused-references-using – Jeeva Subburaj Nov 24 '09 at 08:39
-
14Notifying the duplicate post got duplicated.. funny huh... :) – Jeeva Subburaj Nov 24 '09 at 09:10
-
possible duplicate of [Tools for finding unused references](http://stackoverflow.com/questions/142627/tools-for-finding-unused-references) – Steve Guidi Aug 28 '12 at 02:52
-
2Unfortunately, in `VB.NET` this comes out of the box (built in Visual Studio), but not in `C#` ... :-( – Matt Dec 18 '12 at 16:28
-
Possible duplicate of [Removing all unused references from a project in Visual Studio projects](http://stackoverflow.com/questions/3157066/removing-all-unused-references-from-a-project-in-visual-studio-projects) – IROEGBU Oct 26 '16 at 08:24
6 Answers
I am unaware of such a tool off the top of my head - I do know that Visual Studio does not include one by default. However, referenced assemblies that are not actually used by code in the project are automatically removed by the C# compiler from the list of assemblies referenced by the compiled program. If you use Reflector, you can compare the list of actual references to the list of references in the project, and remove the unnecessary ones that the project includes based on that.

- 97,721
- 20
- 209
- 280
-
-
.NET Reflector is a free (and essential) program from redgate: http://www.red-gate.com/products/reflector/ – Sam Harwell Nov 24 '09 at 08:41
-
Reflector is Redgate Reflector which can be found here: http://www.red-gate.com/products/reflector/ – Murph Nov 24 '09 at 08:46
-
1
-
8Using ILSpy, an open-source .NET assembly browser and decompiler, you can get a list of actual references. Open the assembly in ILSpy and look for the 'References' node. Beware that a reference may contain a reference to another assembly! – mathijsuitmegen Apr 27 '11 at 07:43
JetBrains Resharper adds a menu item Remove Unused References to the References node's context menu in the Solution Explorer.
When you click it, it'll scan you project and list references which can be removed. You can further select which ones you want to remove.

- 23,966
- 9
- 79
- 68
-
It also includes an "Optimize references" option which parses your source code as well to remove nuget and other items. Very useful. – rollsch Jan 31 '17 at 05:00
ResolveUR - Resolve Unused Referencese Unused References
https://marketplace.visualstudio.com/items?itemName=battas.ResolveUR-ResolveUnusedReferences
Works with Visual Studio 2013, 2015, 2017 and 2019

- 4,532
- 4
- 53
- 64
-
Doesn't work with 2019 unless you manually edit installation config files – Tzwenni Dec 30 '20 at 10:53
-
@Tzwenni Works with 2019 16.0 or older... I think you are using 16.5 or newer – Yousha Aleayoub Dec 31 '20 at 06:46
Check out the Productivity Power-tool Plugin
Removing unused references from project is one of the many helpful features it has. It is free and it has some of the R# features.

- 3,706
- 5
- 27
- 42
-
2
-
4This answer is wrong. Productivity power tools can remove unused `using` statements, but not unused references. – BJ Myers Apr 28 '17 at 22:39