DependencyContext 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供有關應用程式相依性的資訊。
public ref class DependencyContext
public class DependencyContext
type DependencyContext = class
Public Class DependencyContext
- 繼承
-
DependencyContext
範例
此範例展示了如何顯示目前應用程式的目標框架及執行時相依關係:
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();
}
備註
當.NET應用程式被編譯時,SDK 會產生一個 JSON 清單檔案(<ApplicationName>.deps.json),其中包含有關應用程式相依性的資訊。 你可以在執行時用這個 DependencyContext 類別讀取這個清單的資訊。
建構函式
| 名稱 | Description |
|---|---|
| DependencyContext(TargetInfo, CompilationOptions, IEnumerable<CompilationLibrary>, IEnumerable<RuntimeLibrary>, IEnumerable<RuntimeFallbacks>) |
初始化 DependencyContext 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| CompilationOptions |
取得編譯應用程式所需的編譯選項。 |
| CompileLibraries |
取得用於編譯應用程式的函式庫清單。 |
| Default |
取得目前應用程式的相依上下文。 |
| RuntimeGraph |
會得到一個執行時識別碼圖。 |
| RuntimeLibraries |
取得應用程式執行時使用的函式庫清單。 |
| Target |
取得應用程式目標執行時的資訊。 |
方法
| 名稱 | Description |
|---|---|
| Load(Assembly) |
載入指定組裝的相依上下文。 |
| Merge(DependencyContext) |
將目前的相依上下文與指定的上下文合併。 |
擴充方法
| 名稱 | Description |
|---|---|
| GetDefaultAssemblyNames(DependencyContext) |
提供有關應用程式相依性的資訊。 |
| GetDefaultNativeAssets(DependencyContext) |
提供有關應用程式相依性的資訊。 |
| GetDefaultNativeRuntimeFileAssets(DependencyContext) |
提供有關應用程式相依性的資訊。 |
| GetRuntimeAssemblyNames(DependencyContext, String) |
提供有關應用程式相依性的資訊。 |
| GetRuntimeNativeAssets(DependencyContext, String) |
提供有關應用程式相依性的資訊。 |
| GetRuntimeNativeRuntimeFileAssets(DependencyContext, String) |
提供有關應用程式相依性的資訊。 |