7

Possible Duplicate:
Tools for finding unused references

I inherited a brownfield project and am in the process of refactoring the code to support new requirements. The number of assembly references has grown considerably over time, and I would like to know if any references are no longer being used. What is the best approach to this other than dropping the reference and trying to re-compile the code.

Community
  • 1
  • 1
Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119
  • possible duplicate? http://stackoverflow.com/questions/81597/remove-unused-references-using-visual-studio – Metro Smurf Oct 08 '09 at 16:38
  • Dupe: http://stackoverflow.com/questions/142627/tools-for-finding-unused-references – Shay Erlichmen Oct 08 '09 at 16:41
  • 1
    Reopened because the question it is a duplicate of is gone. (The other question was explicitly a tool request, which is verboten, this question is a specific problem which may be answered in ways with and without external tools, which is allowed) – Ben Voigt Jul 26 '19 at 15:01

5 Answers5

4

You can do this with Resharper by JetBrains.

Just right click on a reference, and choose "Find Dependent Code". It will search the project and tell you exactly what is referencing an assembly.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • This is the way to go for "normal" projects, but what about web projects were you don't have a References folder in the Solution Explorer? – mbx Mar 16 '12 at 09:18
1

I would suggest checking out NDepend. It gives you not only an idea for what assemblies reference other assemblies, but also a list of dependencies across them.

Joseph
  • 25,330
  • 8
  • 76
  • 125
  • Where is this in NDepdend? I've searched before, but don't see something that will tell you specifically whether a dependency on a specific assembly can be specified in CQL. – Reed Copsey Oct 08 '09 at 16:39
  • You have several choice to see asm not used Use the Dependency Graph (see which box has no incoming arrow) Use the Dependency Matrix (see which row is empty) Use CQL: SELECT ASSEMBLIES WHERE AsmCa == 0 this query will return assemblies with no user. Btw, having many assemblies is a bad thing: http://codebetter.com/blogs/patricksmacchia/archive/2008/12/08/advices-on-partitioning-code-through-net-assemblies.aspx – Patrick from NDepend team Oct 09 '09 at 08:43
0

Resharper suggests to add references if you used classes form dll that is not referenced, you can delete all references and add them back by resharper

Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
0

Interesting enough, VB.NET projects do have an option that will do this, C# does not (that I have found). Resharper will allow you to right click on a reference and "Find Dependent Code".

NerdFury
  • 18,876
  • 5
  • 38
  • 41
0

Peli's Assembly Graph can show your assembly dependency graphs. It's a free add-in for .NET Reflector.

TrueWill
  • 25,132
  • 10
  • 101
  • 150