using System; using NuGet.Packaging.Core; public class MyPackage : IPackage { public PackageIdentity Identity { get; } public string Description { get; } public IEnumerableDependencyGroups { get; } public IEnumerable GetContentFiles() { } // implementation of other IPackage members }
using System.Collections.Generic; using System.Runtime.Versioning; using Microsoft.Extensions.DependencyModel; public class MyApp { public void LoadDependencies() { var context = DependencyContext.Default; var compilationAssemblies = context.CompileLibraries .Where(l => !l.Serviceable && l.Type == "package" && l.Dependencies.Count == 0) .SelectMany(l => l.ResolveReferencePaths()); // use the resolved assembly paths here } }This example demonstrates the use of the IPackage-related types in the Microsoft.Extensions.DependencyModel package, which provides a way to load and manage dependencies in .NET Core applications. The LoadDependencies method uses the DependencyContext.Default object to get a list of all the compile-time libraries in the application, and then filters out any libraries that are not packaged (i.e. part of the runtime environment) and have no dependencies of their own. The resulting list of assemblies is then used in some way by the application. Package library: Microsoft.Extensions.DependencyModel.