0

I am in the process of writing a document analyzing a large codebase for quality and maintainability. As part of this report I wish to include a count of the number of references an assembly makes to another assembly within the solution. This will give an idea of how tightly coupled each assembly is to another.

Is there a tool in Visual Studio 2015 Enterprise (or 3rd Party Plug-In) that can give me this number?

So far I have tried Visual Studio's Code Map tool but this appears to just generate a visualization with arrows which I would then have to count manually and futhermore this only appears to be to class/struct-level, not the number of individual references within each class/struct.

Sphynx
  • 135
  • 2
  • 12

3 Answers3

1

NDepend (http://www.ndepend.com/) offers this functionality. It can be also be quite helpful in more general terms for the type of exploratory quality analysis that you describe.

Nicole Calinoiu
  • 20,843
  • 2
  • 44
  • 49
  • I had used the trial of this tool previously for another task. It did appear to offer features not offered by other code analysis tools I have used. Unfortunately my trial has since expired, I might have to convince my line manager into making the purchase if there are no alternative solutions. – Sphynx Jan 27 '16 at 17:54
  • I have just had a collegue download the trial and run an analysis against the solution. I think the specific figures I was after are contained in the "Dependency Matrix". The count in blue being number of times referenced, the count in green being the number of references the assembly in question has made to other assemblies. I'll add my own answer as I have a screenshot to include. Thanks for pointing me in the right direction. – Sphynx Jan 28 '16 at 10:40
0

You can use FxCop / Code Analysis to do this, this has a number of maintainability rules, of most interest to you would probably be:

CA1506: Avoid excessive class coupling
This rule measures class coupling by counting the number of unique type references that a type or method contains.

I believe the thresholds are 80 for a class and 30 for a method.

It's relatively easy to set up, basically you just need to configure it on a project:

enter image description here

Opening the ruleset lets you choose which ones to run (and whether they are warnings or errors), there are many, many rules.

NikolaiDante
  • 18,469
  • 14
  • 77
  • 117
  • This is useful but I don't think it's exactly what I'm after. I'm looking to get the actual number of references one assembly makes to another. As I understand it, the number of CA1506 warnings returned per project would instead be equal to the number of types which contain 80 or more distinct references to other types plus the number of methods which contain 30 or more distinct references to non-containing types. Is my understanding of this correct? – Sphynx Jan 27 '16 at 10:06
  • I have been investigating into the usage of FxCopCmd.exe (the standalone command-line version of the Code Analysis tool). It appears to accept an XSL file as an argument to transform the output to at least obtain the number of CA1506 warnings per file name or namespace but it's still not the number I'm after. As a side note, the tool returns "[Location not stored in Pdb]" against each file name for some reason which means I don't even have the file name to work against. – Sphynx Jan 27 '16 at 17:51
0

To expand upon Nicole's answer, I have tested the trial of NDepend and I believe I have found the figures I was looking for in something they call the "Dependency Matrix". My understanding of it is as follows.

The numbers in green are a count of how many times the assembly in the current row references the assembly relating to the number in the current column. The numbers in blue are a count of how many times the assembly in the current row is referenced by the assembly relating to the number in the current column. Since an assembly cannot make an external reference to itself, no numbers can appear on the diagonal line.

Dependdency Matrix

What I do no understand however is why, for example, the number in cell 0, 4 is 93 but the number in cell 4, 0 is 52; shouldn't these numbers be equal? Assembly 0 is only used by assembly 4 the same number of times as assembly 4 uses assembly 0 - how can these numbers be different?

UPDATE: I have watched a PluralSight video on this tool and found out that the number in the green box represents how many methods in the referencing assembly make reference to the referenced assembly. The number in the corresponding blue box represents how many methods in the referenced assembly are being used by the referencing assembly. Neither of these numbers precisely represent the number of calls one assembly makes to another (since a method could contain multiple references) but I believe it does provide a sufficient level of granuarity anyway since methods should conform to SRP and thus all references within a method should relate to a single behaviour.

Sphynx
  • 135
  • 2
  • 12