12

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?

0

5 Answers 5

11

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)

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for providing the quickest path to a solution. In under two minutes I fired up PowerShell, ran your script, pasted the output into yuml.me and generated a graph. Very nice! BTW, the code on your linked blog post produces slightly cleaner output than your abbreviated version here--this one throws in "[project] -> []" for projects lacking references. (It appears that yuml generates the same graph either way, though.)
10

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

Comments

3

In addition to NDepend, you can also try this addin for Reflector for showing assembly dependency graph.

Comments

2

You can create a dependency graph of projects and assemblies in Visual Studio 2010 Ultimate by using Architecture Explorer to browse your solution, select projects and the relationships that you want to visualize, and then create a dependency graph from your selection.

For more info, see the following topics:

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

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

Comments

0

Structure101 can do that. You can browse a model by assembly and/or namespace, and clicking on any dependency at any level give you all the code-level references that cause the dependency. The .NET version is in beta, but it's been available for other languages for years, so it's very mature. Here's an example screen shot. alt text http://www.headwaysoftware.com/images/assemblies.jpg

1 Comment

The link is dead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.