Dependency graph of Visual Studio projects

2019-01-08 03:35发布

问题:

I'm currently migrating a big solution (~70 projects) from VS 2005 + .NET 2.0 to VS 2008 + .NET 3.5. Currently I have VS 2008 + .NET 2.0.

The problem is that I need to move projects one by one to new .NET framework ensuring that no .NET 2.0 project references .NET 3.5 project. Is there any tool that would give me a nice graph of project dependencies?

回答1:

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



回答2:

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"



回答3:

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

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

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 =)


回答4:

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.



回答5:

I wrote a tool that might help you. VS Solution Dependency Visualizer analyzes project dependencies within a solution and create a dependency chart from this information, as well as a text report.



回答6:

You can create a dependency graph of your projects in VS 2010 Ultimate. Architecture Explorer lets you 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



回答7:

I had a similar issue, but it was further complicated because several projects were referencing different versions of the same assembly.

To get an output that includes version information and checks for possible runtime assembly loading issues, I made this tool:

https://github.com/smpickett/DependencyViewer

(direct link to github release: https://github.com/smpickett/DependencyViewer/releases)



回答8:

To complete the eriawan answer on graphs generated by NDepend see screenshoots below. You can download and use the free trial edition of NDepend for a while.

More on NDepend Dependency Graph

More on NDepend Dependency Matrix:

Disclaimer: I am part of the tool team



回答9:

If you simply want a dependency graph I've found this is one of the cleanest ways to get one:

Dependency Analyser



回答10:

You can create a nice graph of the references in your projects. I've described the way I did it on my blog http://www.mellekoning.nl/index.php/2010/03/11/project-references-in-ddd/



回答11:

I created a little C# project using YUML as the output.. the code can be found here:

https://github.com/twistedtwig/DotnetProjectDependencyGraphs



回答12:

The Powershell solution is the best. I adapted it into a bash script that works on my machine (TM):

#!/bin/bash

for i in `find . -type f -iname "*.csproj"`; do
    # get only filename
    project=`basename $i`

    # remove csproj extension
    project=${project%.csproj}

    references=`cat $i | grep '<ProjectReference' | cut -d "\"" -f 2`
    for ref in $references; do
        # keep only filename (assume Windows paths)
        ref=${ref##*\\}

        # remove csproj extension
        ref=${ref%.csproj}

        echo "[ $project ] -> [ $ref ]"
    done

done