Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency graph of Visual Studio projects

People also ask

What is dependency graph explain with example?

A dependency graph is a data structure formed by a directed graph that describes the dependency of an entity in the system on the other entities of the same system. The underlying structure of a dependency graph is a directed graph where each node points to the node on which it depends.


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"

Update: ReSharper since version 8 has built-in 'View Project Dependencies' feature.

ReSharper version prior to 8 has Internal feature to show dependency graphs in using yFiles viewer. See quick manual in the bottom of the post.

enter image description here

Howto

  1. Install yEd tool from here.
  2. Run VS with /resharper.internal command line argument.
  3. Go to ReSharper/Internal/Show Dependencies.
  4. Specify projects that you want to include to the 'big picture'.
  5. Uncheck 'Exclude terminal nodes...' unless you need it.
  6. Press 'Show'.
  7. Use hierarchical layout in yEd (Alt+Shift+H)
  8. Provide feedback =)

Have you tried NDepend? It'll shows you the dependencies and you can also analyze the usability of your classes and methods.

Their website:

http://ndepend.com


To complete the @Eriawan answer in April 2020 NDepend version 2020.1 has been released with Dependency Graph completely rebuilt. It now scales on large solutions made of hundreds of projects and offers many navigation facilities.

Here is what it looks like on the NopCommerce OSS project.

NDepend Dependency Graph on NopCommerce

Here is what it looks like on the entire .NET Core 3 classes library (176 assemblies).

enter link description here

Disclaimer: I work at NDepend


You can get a project dependency graph easily using Visual Studio 2010 Ultimate, scan to 5 minutes into this video to see how: http://www.lovettsoftware.com/blogengine.net/post/2010/05/27/Architecture-Explorer.aspx

In Visual Studio 2010 Ultimate: Architecture | Generate Dependency Graph | By Assembly.