Description
ClassDep is an add-in which generates a JPEG or JPG image showing an inheritance and/or
a dependency graph of a C++ project in visual studio. is uses the graphviz tools from
http://www.research.att.com/sw/tools/graphviz/.
The picture above shows the generated dependency graph of one of my projects.
Installation
Just double-click on the msi file and follow the installation instructions. All files from the graphviz library
are included in the msi file.
Usage
to use the addin simply click on the ClassDep-Entry in the Tool-Menu of
Visual Studio .NET. It only works
for C++ projects (C# and VB are not supported). The resulting picture files are stored in the corresponding
project folder with the name(s) projectdep.jpg and/or projectdep.png.
Please note that the picture files may become really huge for big projects!
Implementation
for generating inheritance/dependency graphs it is usually necessary to parse the
source code. but you sure have
already noticed that visual studio does that in the "class-view"-window - it shows the base classes and the members
of all project classes. So I wondered if and how I could use this built-in functionality of visual studio for
my needs. the DTE-object was the perfect solution:
Dim applicationObject As EnvDTE.DTE
Dim project As Project
For Each project In applicationObject.ActiveSolutionProjects()
BuildObjectList(project.CodeModel.CodeElements, 0)
For Each cl In project.CodeModel.CodeElements
If (cl.Kind = vsCMElement.vsCMElementClass) Then
ScanBases(cl, 0)
depfile.WriteLine(";")
If (ob.dependency.Checked) Then
ScanDependencies(cl)
End If
End If
Next
I started first with a macro and then decided to switch to an add-in because of the easier installation.
That's the reason why this add-in is written in VB.
one problem of an addin is that I don't know a way to get the path of where the addin-dll is installed. that is also
the path where the graphviz files are installed and I need to know that to use these files. the only way I know of is
by using the registry. So the installation msi writes also a registry entry with the installation path:
Dim dotdir As String
dotdir = Registry.LocalMachine.OpenSubKey( _
"Software\Microsoft\VisualStudio\7.0\AddIns\ClassDep.Connect", _
False).GetValue("instpath", " ")
and last the call to the graphviz tools:
If ob.outjpeg.Checked Then
Shell(dotdir + "\dot.exe -Tjpg """ + dir + "dep.txt"" -o """ + dir +_
project.Name + "dep.jpg""", AppWinStyle.MinimizedFocus, True)
End If
If ob.outpng.Checked Then
Shell(dotdir + "\dot.exe -Tpng """ + dir + "dep.txt"" -o """ + dir +_
project.Name + "dep.png""", AppWinStyle.MinimizedFocus, True)
End If
Conclusion
There are a lot of improvements possible like a better ordering of the dependency graph and
the like. Some of you
might find the colors awful - feel free to change that :-)
I also included the graphviz files inside the msi-installer. As far as I understand the
license of the graphviz this
is allowed - mail me if I'm wrong.
If someone knows how to change that ugly smiley-icon of the menu-entry please let me know!
History
July 9 2002 - updated setup download.
July 15 2002 - fixed uncaught exception bug found by Brian D Pearson