Skip to content

Commit 3420dae

Browse files
Add documentation for DependencyContext (dotnet#7735)
1 parent fae2d2f commit 3420dae

File tree

4 files changed

+124
-28
lines changed

4 files changed

+124
-28
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using Microsoft.Extensions.DependencyModel;
3+
4+
namespace DependencyContextSnippets
5+
{
6+
class DependencyContextSnippets
7+
{
8+
static void PrintDependencyInformation()
9+
{
10+
//<SnippetPrintDependencyInformation>
11+
Console.WriteLine($"Target framework: {DependencyContext.Default.Target.Framework}");
12+
Console.WriteLine();
13+
Console.WriteLine("Runtime libraries:");
14+
Console.WriteLine();
15+
16+
foreach (RuntimeLibrary lib in DependencyContext.Default.RuntimeLibraries)
17+
{
18+
if (lib.Dependencies.Count > 0)
19+
{
20+
Console.WriteLine($"{lib.Name} depends on: ");
21+
22+
foreach (Dependency dep in lib.Dependencies)
23+
{
24+
Console.WriteLine($"- {dep.Name}, Version {dep.Version}");
25+
}
26+
}
27+
else
28+
{
29+
Console.WriteLine($"{lib.Name} does not have dependencies");
30+
}
31+
32+
Console.WriteLine();
33+
}
34+
//</SnippetPrintDependencyInformation>
35+
}
36+
37+
public static void Run()
38+
{
39+
PrintDependencyInformation();
40+
}
41+
}
42+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="6.0.0" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace DependencyContextSnippets
4+
{
5+
class Program
6+
{
7+
static void Main()
8+
{
9+
DependencyContextSnippets.Run();
10+
}
11+
}
12+
}

xml/Microsoft.Extensions.DependencyModel/DependencyContext.xml

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@
1616
</Base>
1717
<Interfaces />
1818
<Docs>
19-
<summary>To be added.</summary>
20-
<remarks>To be added.</remarks>
19+
<summary>Provides information about application dependencies.</summary>
20+
<remarks>
21+
<format type="text/markdown"><![CDATA[
22+
23+
## Remarks
24+
25+
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.
26+
27+
## Examples
28+
29+
This example shows how to display the current application's target framework and run-time dependencies:
30+
31+
:::code language="csharp" source="~/snippets/csharp/Microsoft.Extensions.DependencyModel/DependencyContext/Overview/DependencyContextSnippets.cs" id="SnippetPrintDependencyInformation":::
32+
33+
]]></format>
34+
</remarks>
2135
</Docs>
2236
<Members>
2337
<Member MemberName=".ctor">
@@ -42,12 +56,12 @@
4256
<Parameter Name="runtimeGraph" Type="System.Collections.Generic.IEnumerable&lt;Microsoft.Extensions.DependencyModel.RuntimeFallbacks&gt;" />
4357
</Parameters>
4458
<Docs>
45-
<param name="target">To be added.</param>
46-
<param name="compilationOptions">To be added.</param>
47-
<param name="compileLibraries">To be added.</param>
48-
<param name="runtimeLibraries">To be added.</param>
49-
<param name="runtimeGraph">To be added.</param>
50-
<summary>To be added.</summary>
59+
<param name="target">Target runtime information.</param>
60+
<param name="compilationOptions">Compilation options.</param>
61+
<param name="compileLibraries">Compilation libraries.</param>
62+
<param name="runtimeLibraries">Runtime libraries.</param>
63+
<param name="runtimeGraph">Runtime identifiers graph.</param>
64+
<summary>Initializes a new instance of the <see cref="T:Microsoft.Extensions.DependencyModel.DependencyContext" /> class.</summary>
5165
<remarks>To be added.</remarks>
5266
</Docs>
5367
</Member>
@@ -69,8 +83,8 @@
6983
<ReturnType>Microsoft.Extensions.DependencyModel.CompilationOptions</ReturnType>
7084
</ReturnValue>
7185
<Docs>
72-
<summary>To be added.</summary>
73-
<value>To be added.</value>
86+
<summary>Gets the compilation options used to compile the application.</summary>
87+
<value>The compilation options used to compile the application.</value>
7488
<remarks>To be added.</remarks>
7589
</Docs>
7690
</Member>
@@ -92,9 +106,17 @@
92106
<ReturnType>System.Collections.Generic.IReadOnlyList&lt;Microsoft.Extensions.DependencyModel.CompilationLibrary&gt;</ReturnType>
93107
</ReturnValue>
94108
<Docs>
95-
<summary>To be added.</summary>
96-
<value>To be added.</value>
97-
<remarks>To be added.</remarks>
109+
<summary>Gets the list of libraries used to compile the application.</summary>
110+
<value>The list of libraries used to compile the application.</value>
111+
<remarks>
112+
<format type="text/markdown"><![CDATA[
113+
114+
## Remarks
115+
116+
This property is only fully populated when the [PreserveCompilationContext](/dotnet/core/project-sdk/msbuild-props#preservecompilationcontext) project property is set to `True`. Otherwise, the contents of this property might be incomplete or empty.
117+
118+
]]></format>
119+
</remarks>
98120
</Docs>
99121
</Member>
100122
<Member MemberName="Default">
@@ -122,8 +144,8 @@
122144
<ReturnType>Microsoft.Extensions.DependencyModel.DependencyContext</ReturnType>
123145
</ReturnValue>
124146
<Docs>
125-
<summary>To be added.</summary>
126-
<value>To be added.</value>
147+
<summary>Gets the dependency context for the current application.</summary>
148+
<value>The dependency context for the current application.</value>
127149
<remarks>To be added.</remarks>
128150
</Docs>
129151
</Member>
@@ -155,9 +177,9 @@
155177
<Parameter Name="assembly" Type="System.Reflection.Assembly" />
156178
</Parameters>
157179
<Docs>
158-
<param name="assembly">To be added.</param>
159-
<summary>To be added.</summary>
160-
<returns>To be added.</returns>
180+
<param name="assembly">The assembly to load dependency context for.</param>
181+
<summary>Loads the dependency context for the specified assembly.</summary>
182+
<returns>The dependency context for the specified assembly, or <c>null</c> when dependency context is not available.</returns>
161183
<remarks>To be added.</remarks>
162184
</Docs>
163185
</Member>
@@ -182,9 +204,9 @@
182204
<Parameter Name="other" Type="Microsoft.Extensions.DependencyModel.DependencyContext" />
183205
</Parameters>
184206
<Docs>
185-
<param name="other">To be added.</param>
186-
<summary>To be added.</summary>
187-
<returns>To be added.</returns>
207+
<param name="other">The dependency context to merge.</param>
208+
<summary>Merges the current dependency context with the specifed one.</summary>
209+
<returns>The dependency context that results from merging dependencies of the current context with the specified one.</returns>
188210
<remarks>To be added.</remarks>
189211
</Docs>
190212
</Member>
@@ -206,9 +228,17 @@
206228
<ReturnType>System.Collections.Generic.IReadOnlyList&lt;Microsoft.Extensions.DependencyModel.RuntimeFallbacks&gt;</ReturnType>
207229
</ReturnValue>
208230
<Docs>
209-
<summary>To be added.</summary>
210-
<value>To be added.</value>
211-
<remarks>To be added.</remarks>
231+
<summary>Gets a runtime identifiers graph.</summary>
232+
<value>A runtime identifiers graph.</value>
233+
<remarks>
234+
<format type="text/markdown"><![CDATA[
235+
236+
## Remarks
237+
238+
A runtime identifiers graph indicates which runtimes are compatible with each other. For more information, see [.NET RID Catalog](/dotnet/core/rid-catalog).
239+
240+
]]></format>
241+
</remarks>
212242
</Docs>
213243
</Member>
214244
<Member MemberName="RuntimeLibraries">
@@ -229,8 +259,8 @@
229259
<ReturnType>System.Collections.Generic.IReadOnlyList&lt;Microsoft.Extensions.DependencyModel.RuntimeLibrary&gt;</ReturnType>
230260
</ReturnValue>
231261
<Docs>
232-
<summary>To be added.</summary>
233-
<value>To be added.</value>
262+
<summary>Gets the list of libraries used by the application at run time.</summary>
263+
<value>The list of libraries used by the application at run time.</value>
234264
<remarks>To be added.</remarks>
235265
</Docs>
236266
</Member>
@@ -252,8 +282,8 @@
252282
<ReturnType>Microsoft.Extensions.DependencyModel.TargetInfo</ReturnType>
253283
</ReturnValue>
254284
<Docs>
255-
<summary>To be added.</summary>
256-
<value>To be added.</value>
285+
<summary>Gets information about the application's target runtime.</summary>
286+
<value>The application's target runtime information.</value>
257287
<remarks>To be added.</remarks>
258288
</Docs>
259289
</Member>

0 commit comments

Comments
 (0)