.NET Core 依赖树 [英] .NET Core Dependency Tree
问题描述
是否可以在 .net core 应用程序中查看项目的依赖关系?我正在使用 Visual Studio 2017 Professional
.
Is it possible to view dependencies for a project in a .net core application? I'm using Visual Studio 2017 Professional
.
目前,我的 csproj
中引用了以下 nugget 包.
At the moment I have the following nugget packages referenced in my csproj
.
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.1" />
<PackageReference Include="SimpleInjector.Integration.AspNetCore.Mvc" Version="4.0.8" />
</ItemGroup>
在哪里可以导航依赖项.
Where you can navigate dependencies.
但是很难找到特定的依赖项 - 如果您知道要查找的内容,则树是很好的.有没有办法输出依赖程序集和版本的平面列表?
But it makes it hard to find a particular dependency - a tree is good if you know what you are looking for. Is there a way to output a flat list of dependant assemblies and there versions?
推荐答案
您可以将 msbuild 目标添加到您的项目文件中(在
元素内),如下所示:
You can add an msbuild target to your project file (inside the <Project>
element) like this:
<Target Name="PrintAllReferences" DependsOnTargets="RunResolvePackageDependencies">
<Message Importance="high" Text="Referenced package: %(PackageDefinitions.Identity)" />
</Target>
你可以这样调用(没有父包名的一行表示被项目直接引用):
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:
<Target Name="PrintPackagesAndParents" DependsOnTargets="RunResolvePackageDependencies">
<Message Importance="high" Text="* %(PackageDependencies.Identity) referenced by:%0a^---@(PackageDependencies->'%(ParentPackage) - target %(ParentTarget)', '%0a^---')" />
</Target>
产生以下输出:
$ 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
…
没有关于这些项目的真正文档,但它们具有公共"名称并且由 ResolvePackageDependencies 任务,作为 运行ResolvePackageDependencies: 初始化目标和非常有用的<代码>目标项、PackageDefinitions
、PackageDependencies
、FileDependencies
和 DiagnosticMessages
.
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
.
这篇关于.NET Core 依赖树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!