Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I build a 'dependency tree diagram' from my .NET solution

I can get easily see what projects and dlls a single project references from within a Visual Studio .NET project.

Is there any application or use of reflection that can build me a full dependency tree that I can use to plot a graphical chart of dependencies?

like image 354
johnc Avatar asked Sep 17 '08 05:09

johnc


People also ask

How do I find the dependency tree in Visual Studio?

In this post lets have a quick look how you can view the project dependency in Visual Studio. To view the Project Dependencies, Right Click on the Solution and select “Project Dependencies…” as shown in the image below. As shown in the above pictures all the dependent projects are “Checked” .


2 Answers

NDepend comes with an interactive dependency graph coupled with a dependency matrix. You can download and use the free trial edition of NDepend for a while.

More on NDepend Dependency Graph enter image description here

More on NDepend Dependency Matrix: enter image description here

Disclaimer: I am part of the tool team

like image 56
Patrick from NDepend team Avatar answered Sep 27 '22 19:09

Patrick from NDepend team


I needed something similar, but didn't want to pay for (or install) a tool to do it. I created a quick PowerShell script that goes through the project references and spits them out in a yuml.me friendly-format instead:

Function Get-ProjectReferences ($rootFolder)
{
    $projectFiles = Get-ChildItem $rootFolder -Filter *.csproj -Recurse
    $ns = @{ defaultNamespace = "http://schemas.microsoft.com/developer/msbuild/2003" }

    $projectFiles | ForEach-Object {
        $projectFile = $_ | Select-Object -ExpandProperty FullName
        $projectName = $_ | Select-Object -ExpandProperty BaseName
        $projectXml = [xml](Get-Content $projectFile)
        
        $projectReferences = $projectXml | Select-Xml '//defaultNamespace:ProjectReference/defaultNamespace:Name' -Namespace $ns | Select-Object -ExpandProperty Node | Select-Object -ExpandProperty "#text"
        
        $projectReferences | ForEach-Object {
            "[" + $projectName + "] -> [" + $_ + "]"
        }
    }
}

Get-ProjectReferences "C:\Users\DanTup\Documents\MyProject" | Out-File "C:\Users\DanTup\Documents\MyProject\References.txt"

Sample Graph
(source: yuml.me)

like image 38
Danny Tuppeny Avatar answered Sep 27 '22 17:09

Danny Tuppeny