微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.net-core – .NET核心依赖树

是否可以在.net核心应用程序中查看项目的依赖项?我正在使用Visual Studio 2017 Professional.

目前我在csproj中引用了以下nugget包.

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

您可以在哪里导航依赖项.

但是它很难找到一个特定的依赖 – 如果你知道你在寻找什么,树是好的.有没有办法输出依赖程序集的平面列表和那些版本?

您可以将msbuild目标添加到项目文件中(在< Project>元素内),如下所示:
<Target Name="PrintAllReferences" DependsOnTargets="ResolvePackageDependenciesForBuild">
  <Message Importance="high" Text="Referenced package: %(PackageDeFinitions.Identity)" />
</Target>

您可以这样调用(没有父包名称的行意味着它直接由项目引用):

$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
  …

如果你想要一个“反向依赖树” – 一个包列表和哪些包引用它们 – 你可以做类似的事情:

<Target Name="PrintPackagesAndParents" DependsOnTargets="ResolvePackageDependenciesForBuild">
  <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任务生成,该任务作为RunResolvePackageDependencies目标的一部分执行并生成一些非常有用的项目:TargetDeFinitions,PackageDeFinitions,PackageDependencies,FileDependencies和Diagnosticmessages .

原文地址:https://www.jb51.cc/javaschema/281669.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐