2

I am working on splitting up a repo among multiple, mostly separate sub-projects. There is one large project that all the projects reference. I am looking for a way to get a list of classes in the shared project that are only used in one of the sub-projects, so as to build a candidate list of classes that could be removed from the shared project. The end goal is that the shared project only contains shared code.

I can do a lot of this using reflection, but I have an NDepend license, and it seems like this is something I should be able to do using NDepend. How would I do this using NDepend?

Erick T
  • 7,009
  • 9
  • 50
  • 85

1 Answers1

0

You can achieve this with a single CQLInq code query

let myAsm = Application.Assemblies.WithName("YourAsmName").Single()
from a in Application.Assemblies where a.IsUsing(myAsm)
select new { 
   a, 
   typesUsed = myAsm.ChildTypes.UsedBy(a) }

et voilà!

NDepend lists types usage

Certainly the NDepend dependency matrix can help as well, first export assemblies users to matrix columns.

Export Assemblies to NDepend Dependency Matrix

second export your assembly types to matrix rows, this can be with such code query, just export result types to rows this times,

let myAsm = Application.Assemblies.WithName("YourAsmName").Single()
from t in myAsm.ChildTypes select t

and now you can explore all the dependencies, and dig into them.

NDepend Dependency Matrix

Of course you can refine these code queries to get exactly what you need in query result and on matrix.

If you have a few dozens of assemblies and types, you can try exporting to the NDepend dependency graph instead of exporting to the matrix, but it might look messy with too many nodes, the matrix is more adapted to deal with many nodes.

Patrick from NDepend team
  • 13,237
  • 6
  • 61
  • 92