Easy .NET architecture analysis from within VS2005 - Visualizing your code dependencies with a Dependency Structure Matrix

Constant software quality assessment might be deemed important by almost all developers. But it´s a long way from agreeing or preaching something to actually living it in your projects. It often needs good tools to make theory easy to implement in practice. NUnit, NMock, NAnt, ReSharper are examples of such tools which make testing, building, refining your code easier. And NDepend could be one such tool too for quality assessment - but at least in my view it tries to do too much to be easy to adopt while being under pressure in a tight project schedule.

In an earlier posting I showed Dependency Structure Matrices (DSM, Fig. 1) using a tool called Lattix LDM as an alternative to NDepend. I deem it easy to use and understand and not too expensive. I find it quite intuitive to start a habit of constant quality assessment with.


Fig. 1: Sample DSM showing the pretty wellformed dependencies within the .NET Framework WinForms subsystem.

However, so far its Java heredity made it more difficult to use than necessary. But this has changed now! The most recent relase (version 2.7.2) which came out on Sep 8 2006 supports a number of command line parameters which allows for an integration into VS2005 as an External Tool (Fig. 2).


Fig. 2: Setup for Lattix LDM as an External Tool in VS2005

Enter the path to the Lattix LDM executable into the Command field of the External Tool dialog of the Tools menu in VS2005. Then add the following line into the Arguments field:

-process:dotnet "$(ProjectDir)$(ProjectFileName).ldz" "*.exe" "*.dll" -createFileSubsystem -save

This means, the tool is used in .NET-mode (-process:dotnet), creates or updates a DSM project file (file extension .ldz) in the VS2005 project directory and with the name of the VS2005 project ("$(ProjectDir)$(ProjectFileName).ldz", e.g. "c:\myproject\myassembly.csproj.ldz"), analyzes all EXE and all DLL assemblies in the output directory ("*.exe" "*.dll"), and creates DSM subsystems for each assembly (see the larger squares in Fig. 1 as examples for subsystems). -save tells Lattix LDM to save the resulting DSM.

Set the Initial Directory for the External Tool to the Debug or Release directory of the VS2005 project and off you go... Just click on a project in your VS2005 solution and call your new External Tool. Lattix LDM will start and generate (or update) a DSM for your .NET project in no time. You can then rearrange the subsystems to find patterns in your dependencies. This works best if used on an "integration project" in your solutions, e.g. a Winforms or Console assembly referencing other projects/assemblies.

With this External Tool in place checking a project´s basic architecture is a snap. And it´s interesting to see how one can quickly get addicted to a "green bar" regarding architecture; seeing a clean DSM after some work on your solution is like running all your unit tests again and getting a "green bar". It lets you sleep better at night :-)

PS: Here´s an overview of the Lattix LDM command line options:

Just open an existing DSM file:

lattixldm <file.ldz>

Create/update a DSM file from a set of assemblies:

lattixldm -process:dotnet [<file.ldz>] [-input files] [Component Options] [-createFileSubsystem] [-flatSubsystems] [-save]

 

Component Options:
  -dotnet_include_prefix:<Class Namespace Prefix>[,<Class Namespace Prefix>...]
  -logfile:<File Name>

-createFileSubsystem: A subsystem will be created for each input source specified in the project.
-flatSubsystems: All subsystems will be created as siblings with no hierarchy.

PPS: Some people speculated whether I have any commercial interest in Lattix LDM, since I´m sounding so excited about it. Well, the truth is: I don´t receive any money from Lattix Inc, I don´t have any shares of them (if there exist any ;-), I don´t sell their tool. I just stumbled across it and found it exciting. That´s it. And this can happen again any day with some other tool - about which I then might write equally excited. In a .NET world, where everybody seems either "super excited" about Microsofts technologies, some hype like SOA, or some Open Source project, why -just for a change - shouldn´t I be excited about something completely different: a 3rd party product (like Lattix LDM) or concept (e.g. eXtensible Virtual Shared Memory or a System of Pure Relations like Pile)?

No Comments