Share via


DependencyContext Class

Definition

Provides information about application dependencies.

public ref class DependencyContext
public class DependencyContext
type DependencyContext = class
Public Class DependencyContext
Inheritance
DependencyContext

Examples

This example shows how to display the current application's target framework and run-time dependencies:

Console.WriteLine($"Target framework: {DependencyContext.Default.Target.Framework}");
Console.WriteLine();
Console.WriteLine("Runtime libraries:");
Console.WriteLine();

foreach (RuntimeLibrary lib in DependencyContext.Default.RuntimeLibraries)
{
    if (lib.Dependencies.Count > 0)
    {
        Console.WriteLine($"{lib.Name} depends on: ");

        foreach (Dependency dep in lib.Dependencies)
        {
            Console.WriteLine($"- {dep.Name}, Version {dep.Version}");
        }
    }
    else
    {
        Console.WriteLine($"{lib.Name} does not have dependencies");
    }

    Console.WriteLine();
}

Remarks

When a .NET application is compiled, the SDK generates a JSON manifest file (<ApplicationName>.deps.json) that contains information about application dependencies. You can use the DependencyContext class to read information from this manifest at run time.

Constructors

DependencyContext(TargetInfo, CompilationOptions, IEnumerable<CompilationLibrary>, IEnumerable<RuntimeLibrary>, IEnumerable<RuntimeFallbacks>)

Initializes a new instance of the DependencyContext class.

Properties

CompilationOptions

Gets the compilation options used to compile the application.

CompileLibraries

Gets the list of libraries used to compile the application.

Default

Gets the dependency context for the current application.

RuntimeGraph

Gets a runtime identifiers graph.

RuntimeLibraries

Gets the list of libraries used by the application at run time.

Target

Gets information about the application's target runtime.

Methods

Load(Assembly)

Loads the dependency context for the specified assembly.

Merge(DependencyContext)

Merges the current dependency context with the specifed one.

Extension Methods

GetDefaultAssemblyNames(DependencyContext)
GetDefaultNativeAssets(DependencyContext)
GetDefaultNativeRuntimeFileAssets(DependencyContext)
GetRuntimeAssemblyNames(DependencyContext, String)
GetRuntimeNativeAssets(DependencyContext, String)
GetRuntimeNativeRuntimeFileAssets(DependencyContext, String)

Applies to