.net Visual Studio 项目的依赖关系图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/598129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:14:07  来源:igfitidea点击:

Dependency graph of Visual Studio projects

.netvisual-studiomigrationgraphdependencies

提问by Migol

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.

我目前正在将一个大型解决方案(约 70 个项目)从 VS 2005 + .NET 2.0 迁移到 VS 2008 + .NET 3.5。目前我有 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?

问题是我需要将项目一个一个地移动到新的 .NET 框架,确保没有 .NET 2.0 项目引用 .NET 3.5 项目。有没有什么工具可以给我一个很好的项目依赖关系图?

采纳答案by Eriawan Kusumawardhono

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

你试过NDepend吗?它将向您显示依赖项,您还可以分析类和方法的可用性。

Their website:

他们的网站:

http://ndepend.com

http://ndepend.com



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

为了在 2020 年 4 月完成@Eriawan 的回答,NDepend 2020.1 版已经发布,并且完全重建了依赖关系图。它现在可以扩展由数百个项目组成的大型解决方案,并提供许多导航设施。

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

这是它在NopCommerce OSS 项目上的样子

NDepend Dependency Graph on NopCommerce

NDepend Dependency Graph on NopCommerce

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

以下是整个 .NET Core 3 类库(176 个程序集)的外观。

enter link description here

enter link description here

Disclaimer: I work at NDepend

免责声明:我在 NDepend 工作

回答by Danny Tuppeny

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 referencesand spits them out in a yuml.mefriendly-format instead:

我需要类似的东西,但不想支付(或安装)工具来做到这一点。我创建了一个快速的 PowerShell 脚本,它遍历项目引用并以yuml.me友好格式将它们吐出:

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"

回答by Shkredov S.

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

更新:ReSharper 自第 8 版起具有内置的“查看项目依赖项”功能。

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

ReSharper 版本 < 8 具有使用 yFiles 查看器显示依赖关系图的内部功能。请参阅帖子底部的快速手册。

enter image description here

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 =)
  1. 这里安装 yEd 工具。
  2. 使用 /resharper.internal 命令行参数运行 VS。
  3. 转到 ReSharper/内部/显示依赖项。
  4. 指定要包含在“大图”中的项目。
  5. 除非需要,否则取消选中“排除终端节点...”。
  6. 按“显示”。
  7. 在 yEd 中使用分层布局 (Alt+Shift+H)
  8. 提供反馈 =)

回答by Chris Lovett

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

您可以使用 Visual Studio 2010 Ultimate 轻松获取项目依赖关系图,扫描到此视频 5 分钟以了解操作方法:http: //www.lovettsoftware.com/blogengine.net/post/2010/05/27/Architecture-Explorer .aspx

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

在 Visual Studio 2010 Ultimate 中:架构 | 生成依赖图 | 由大会。

回答by devio

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

我写了一个可能对你有帮助的工具。VS Solution Dependency Visualizer分析解决方案中的项目依赖项,并根据此信息创建依赖项图表以及文本报告。

回答by Pickett

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

https://github.com/smpickett/DependencyViewer

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

(github 发布的直接链接:https: //github.com/smpickett/DependencyViewer/releases

回答by Esther Fan - MSFT

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.

您可以在 VS 2010 Ultimate 中创建项目的依赖关系图。Architecture Explorer 允许您浏览您的解决方案,选择您想要可视化的项目和关系,然后根据您的选择创建一个依赖关系图。

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

如何:从代码生成图形文档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

如何:使用架构资源管理器查找代码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.

RC 下载http: //www.microsoft.com/downloads/details.aspx? displaylang=en&FamilyID=457bab91-5eb2-4b36-b0f4- d6f34683c62a

Visual Studio 2010 Architectural Discovery & Modeling Toolsforum: http://social.msdn.microsoft.com/Forums/en-US/vsarch/threads

Visual Studio 2010 架构探索和建模工具论坛:http: //social.msdn.microsoft.com/Forums/en-US/vsarch/threads

回答by Patrick from NDepend team

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

要完成对 NDepend 生成的图表的 eriawan 答案,请参阅下面的屏幕截图。您可以下载并使用NDepend的免费试用版一段时间。

More on NDepend Dependency Graphenter image description here

更多关于 NDepend 依赖图enter image description here

More on NDepend Dependency Matrix: enter image description here

更多关于 NDepend 依赖矩阵enter image description here

Disclaimer: I am part of the tool team

免责声明:我是工具团队的一员

回答by Hace

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/

您可以在您的项目中创建一个漂亮的参考图。我已经在我的博客http://www.mellekoning.nl/index.php/2010/03/11/project-references-in-ddd/上描述了我的做法

回答by Nikolaos Georgiou

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

PowerShell的解决方案是最好的。我将它改编成一个在我的机器(TM)上运行的 bash 脚本:

#!/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