DependencyContext Class (Microsoft.Extensions.DependencyModel)
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides information about application dependencies.
public ref class DependencyContext
public class DependencyContext
type DependencyContext = class
Public Class DependencyContext
- Inheritance
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.