Are there any utilities that can examine a set of managed assemblies and tell you whether any of the types in one namespace depend on any in another? For example, say I have a MyApp.BusinessRules
namespace and don't want it to access directly anything in MyApp.GUI
, but both namespaces are in the same assembly. My goal is to be able to write a custom MSBuild task that verifies that various coupling rules have not been broken.
So far the only tool I have come across that looks like it might do this is NDepend, but I am wondering if there is a simpler solution.
Reflector does this.
Right click namespace, click Analyze, viola! :)
I am one of the developer of the tool NDepend. Please could you let us know what do you find complicated in NDepend and how you imagine a simpler solution for you?
NDepend comes with 3 different ways to do what you want: Dependency Matrix, Dependency Graph and also you can write some Code Rule over LINQ Query (CQLinq) and rules to detect cycle between namespaces, or enforce some particular dependencies.
For that, the following CQLinq rule can be written, could it be any simpler than that?:
I suspect NDepend is going to be the simplest way to go, to be honest.
However, if you really don't want bits of one assembly from referring to each other, you should almost certainly split the assembly up into more logical units.
You can analyze namespace dependencies with the DSM plugin for .NET Reflector ( I'm its developer)
Once the assemblies are analyzed you can save the project to a file. This file is just XML with a simple structure so you can pass it to a script for custom analysis
[Update]: This plugin is now available in form of a Visual Studio Add-In
You can try the RC release of Visual Studio 2010 Ultimate to generate dependency graphs for .NET code. You can generate a graph of all your assemblies, namespaces, classes, or some combination of these, or you can use Architecture Explorer to select specific artifacts and the relationships that you want to visualize.
You can also create layer diagrams from dependency graphs or from the existing artifacts, draw the permitted dependencies, and then include layer validation as part of the MSBuild process to make sure invalid dependencies aren't introduced:
How to: Generate Graph Documents from Code: http://msdn.microsoft.com/en-us/library/dd409453%28VS.100%29.aspx#SeeSpecificSource
How to: Find Code Using Architecture Explorer: http://msdn.microsoft.com/en-us/library/dd409431%28VS.100%29.aspx
How to: Create Layer Diagrams from Artifacts: http://msdn.microsoft.com/en-us/library/dd465141%28VS.100%29.aspx
Layer Diagram http://i.msdn.microsoft.com/Dd465141.UML_LayerRefReading(en-us,VS.100).png
How to: Validate Code Against Layer Diagrams: http://msdn.microsoft.com/en-us/library/dd409395%28VS.100%29.aspx
RC download: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=457bab91-5eb2-4b36-b0f4-d6f34683c62a.
Visual Studio 2010 Architectural Discovery & Modeling Tools forum: http://social.msdn.microsoft.com/Forums/en-US/vsarch/threads