.NET Core Dependency Tree

前端 未结 3 1935
青春惊慌失措
青春惊慌失措 2020-12-15 07:45

Is it possible to view dependencies for a project in a .net core application? I\'m using Visual Studio 2017 Professional.

At the moment I have the foll

3条回答
  •  攒了一身酷
    2020-12-15 08:08

    You can add an msbuild target to your project file (inside the element) like this:

    
      
    
    

    Which you can call like this (a line without a parent package name means it is referenced by the project directly):

    $ dotnet msbuild /nologo /t:PrintAllReferences
      Referenced package: Microsoft.NETCore.Platforms/1.1.0
      Referenced package: Microsoft.NETCore.Targets/1.1.0
      Referenced package: Microsoft.Win32.Primitives/4.3.0
      Referenced package: NETStandard.Library/1.6.1
      Referenced package: runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0
      Referenced package: runtime.fedora.23-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0
      Referenced package: runtime.fedora.24-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0
      Referenced package: runtime.native.System/4.3.0
      Referenced package: runtime.native.System.IO.Compression/4.3.0
      Referenced package: runtime.native.System.Net.Http/4.3.0
      Referenced package: runtime.native.System.Security.Cryptography.Apple/4.3.0
      Referenced package: runtime.native.System.Security.Cryptography.OpenSsl/4.3.0
      Referenced package: runtime.opensuse.13.2-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0
      Referenced package: runtime.opensuse.42.1-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.0
      Referenced package: System.Buffers/4.3.0
      Referenced package: System.Collections/4.3.0
      …
    

    If you wanted a "reverse dependency tree" - a list of packages and which packages reference them - you can do something similar to:

    
      
    
    

    which produces the following output:

    $ dotnet msbuild /nologo /t:PrintPackagesAndParents
      * JetBrains.Annotations/10.2.1 referenced by:
      ^--- - target .NETStandard,Version=v1.3
      * System.IO.FileSystem.Primitives/4.0.1 referenced by:
      ^---NETStandard.Library/1.6.0 - target .NETStandard,Version=v1.3
      ^---System.IO.Compression.ZipFile/4.0.1 - target .NETStandard,Version=v1.3
      ^---System.IO.FileSystem/4.0.1 - target .NETStandard,Version=v1.3
      ^---System.Xml.ReaderWriter/4.0.11 - target .NETStandard,Version=v1.3
      * System.Linq/4.1.0 referenced by:
      ^---NETStandard.Library/1.6.0 - target .NETStandard,Version=v1.3
      ^---System.Security.Cryptography.Encoding/4.0.0 - target .NETStandard,Version=v1.3
      * System.Linq.Expressions/4.1.0 referenced by:
      ^---NETStandard.Library/1.6.0 - target .NETStandard,Version=v1.3
      * System.Net.Http/4.1.0 referenced by:
      ^---NETStandard.Library/1.6.0 - target .NETStandard,Version=v1.3
      * System.Net.Primitives/4.0.11 referenced by:
      ^---NETStandard.Library/1.6.0 - target .NETStandard,Version=v1.3
      ^---System.Net.Http/4.1.0 - target .NETStandard,Version=v1.3
      ^---System.Net.Sockets/4.1.0 - target .NETStandard,Version=v1.3
      …
    

    There isn't really documentation about these items, but they have "public" name and are generated by the ResolvePackageDependencies task which is executed as part of the RunResolvePackageDependencies target and produces a few very useful items: TargetDefinitions, PackageDefinitions, PackageDependencies, FileDependencies and DiagnosticMessages.

提交回复
热议问题