.NET Core Dependency Tree

Can I view dependencies for a project in a .net application? I am using Visual Studio 2017 Professional .

At the moment, I have the following nugget packages that my csproj link to.

 <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 through dependencies.

addictions

But this makes it difficult to find a certain relationship - a tree is good if you know what you are looking for. Is there a way to display a flat list of dependent assemblies and versions?

+5
source share
1 answer

You can add the mbuild target to the project file (inside the <Project> element) as follows:

 <Target Name="PrintAllReferences" DependsOnTargets="ResolvePackageDependenciesForBuild"> <Message Importance="high" Text="Referenced package: %(PackageDefinitions.Identity)" /> </Target> 

What you can call it this way (a line without the parent name of the package means that the project refers to it 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 want an "inverse dependency tree" - a list of packages and which packages reference them, you can do something similar to:

 <Target Name="PrintPackagesAndParents" DependsOnTargets="ResolvePackageDependenciesForBuild"> <Message Importance="high" Text="* %(PackageDependencies.Identity) referenced by:%0a^ ---@ (PackageDependencies->'%(ParentPackage) - target %(ParentTarget)', '%0a^---')" /> </Target> 

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 … 

The documentation for these elements is actually missing, but they have a β€œpublic” name and are generated using the ResolvePackageDependencies task, which is executed as part of RunResolvePackageDependencies and creates some very useful elements: TargetDefinitions , PackageDefinitions , PackageDependencies , FileDependencies and DiagnosticMessages .

+9
source

Source: https://habr.com/ru/post/1269550/


All Articles