Skip to content

Commit 479d013

Browse files
Split library and package Readme (#78888)
* Split library and package Readme * Fix punctuation * Fix lint issues * Automatically include package readme file if existent * Rename README.md to PACKAGE.md * Move PACKAGE.md into source directory * Reinstate examples in README.md * Update contributing guidelines * Update docs/coding-guidelines/libraries-packaging.md Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
1 parent b5da2c6 commit 479d013

File tree

44 files changed

+424
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+424
-81
lines changed

docs/coding-guidelines/libraries-packaging.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,29 @@ Libraries to be packaged must set `IsPackable` to true. By default, all `librari
4040

4141
Package versions and shipping state should be controlled using the properties defined by the [Arcade SDK](https://github.com/dotnet/arcade/blob/master/Documentation/ArcadeSdk.md#project-properties-defined-by-the-sdk). Typically libraries should not need to explicitly set any of these properties.
4242

43-
Most metadata for packages is controlled centrally in the repository and individual projects may not need to make any changes to these. One property is required to be set in each project: `PackageDescription`. This should be set to a descriptive summary of the purpose of the package, and a list of common entry-point types for the package: to aide in search engine optimization. Example:
43+
Most metadata for packages is controlled centrally in the repository and individual projects may not need to make any changes to these. One property is required to be set in each project: `PackageDescription`. This should be set to a descriptive summary of the purpose of the package. Example:
44+
4445
```xml
45-
<PackageDescription>Logging abstractions for Microsoft.Extensions.Logging.
46-
47-
Commonly Used Types:
48-
Microsoft.Extensions.Logging.ILogger
49-
Microsoft.Extensions.Logging.ILoggerFactory
50-
Microsoft.Extensions.Logging.ILogger&lt;TCategoryName&gt;
51-
Microsoft.Extensions.Logging.LogLevel
52-
Microsoft.Extensions.Logging.Logger&lt;T&gt;
53-
Microsoft.Extensions.Logging.LoggerMessage
54-
Microsoft.Extensions.Logging.Abstractions.NullLogger</PackageDescription>
46+
<PackageDescription>Logging abstractions for Microsoft.Extensions.Logging.</PackageDescription>
5547
```
5648

5749
Package content can be defined using any of the publicly defined Pack inputs: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets
5850

51+
### Package Readme
52+
53+
Packages can include a Markdown Readme file with a short usage documentation. To include a package Readme, create a `PACKAGE.md` file in the library `src` directory. The file will be automatically included in the package and used as a Readme if its name matches this convention.
54+
55+
The package Readme is displayed on the package details page on [NuGet gallery](https://nuget.org/). You can include the following content in it:
56+
57+
- A description of the package purpose.
58+
- Information when package should be used. For example, if the library is included in the shared framework in .NET, but needs to be installed via NuGet on .NET Framework, it should be mentioned.
59+
- Information on how to get started with the package.
60+
- Links to related documentation.
61+
- A list of common entry-point types for the package, with links to their API docs under [.NET API Browser](https://learn.microsoft.com/dotnet/api/).
62+
- A short code example that demostrates the package usage.
63+
64+
For a list of supported Markdown features, see [NuGet documentation](https://learn.microsoft.com/nuget/nuget-org/package-readme-on-nuget-org#supported-markdown-features).
65+
5966
### Build props / targets and other content
6067

6168
Build props and targets may be needed in NuGet packages. To define these, author a build folder in your src project and place the necessary props/targets in this subfolder. You can then add items to include these in the package by defining `Content` items and setting `PackagePath` as follows:

eng/packaging.targets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<!-- Don't include target platform specific dependencies, since we use the target platform to represent RIDs instead -->
1212
<SuppressDependenciesWhenPacking Condition="'$(TargetPlatformIdentifier)' != ''">true</SuppressDependenciesWhenPacking>
1313
<PackageDesignerMarkerFile>$(MSBuildThisFileDirectory)useSharedDesignerContext.txt</PackageDesignerMarkerFile>
14+
<PackageReadmeFile Condition="'$(PackageReadmeFile)' == '' and Exists('PACKAGE.md')">PACKAGE.md</PackageReadmeFile>
1415
<!-- Generate packages for rid specific projects or for allconfigurations during build. -->
1516
<!-- A package isn't generated if in servicing or in runtimelab. Intended to be overridden at project level. -->
1617
<IsRIDSpecificProject Condition="$(MSBuildProjectName.StartsWith('runtime.')) and
@@ -57,6 +58,11 @@
5758
TargetFramework="$(NetFrameworkMinimum)" />
5859
</ItemGroup>
5960

61+
<!-- Add a package README file from. -->
62+
<ItemGroup Condition="'$(PackageReadmeFile)' != ''">
63+
<None Include="$(PackageReadmeFile)" Pack="true" PackagePath="\" />
64+
</ItemGroup>
65+
6066
<Choose>
6167
<When Condition="'$(AddXamarinPlaceholderFilesToPackage)' == 'true' or '$(AddNETFrameworkPlaceholderFileToPackage)' == 'true'">
6268
<PropertyGroup>

src/libraries/Microsoft.Extensions.Configuration.Abstractions/README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
# Microsoft.Extensions.Configuration.Abstractions
22

3-
Provides abstractions of key-value pair based configuration. Interfaces defined in this package are implemented by classes in [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration/) and other configuration packages.
4-
5-
Commonly used types:
6-
7-
- [Microsoft.Extensions.Configuration.IConfiguration](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfiguration)
8-
- [Microsoft.Extensions.Configuration.IConfigurationBuilder](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfigurationbuilder)
9-
- [Microsoft.Extensions.Configuration.IConfigurationProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfigurationprovider)
10-
- [Microsoft.Extensions.Configuration.IConfigurationRoot](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfigurationroot)
11-
- [Microsoft.Extensions.Configuration.IConfigurationSection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfigurationsection)
3+
Provides abstractions of key-value pair based configuration.
124

135
Documentation can be found at https://learn.microsoft.com/dotnet/core/extensions/configuration
146

@@ -41,7 +33,7 @@ Console.WriteLine(options.NamedProperty); // returns "value for named property"
4133
```
4234

4335
## Contribution Bar
44-
- [x] [We consider new features, new APIs, bug fixes, and performance changes](https://github.com/dotnet/runtime/tree/main/src/libraries#contribution-bar)
36+
- [x] [We consider new features, new APIs, bug fixes, and performance changes](../README.md#contribution-bar)
4537

4638
The APIs and functionality are mature, but do get extended occasionally.
4739

src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/Microsoft.Extensions.Configuration.Abstractions.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
<PropertyGroup>
44
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
55
<EnableDefaultItems>true</EnableDefaultItems>
6-
<IsPackable>true</IsPackable>
76
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
7+
<IsPackable>true</IsPackable>
88
<PackageDescription>Provides abstractions of key-value pair based configuration. Interfaces defined in this package are implemented by classes in Microsoft.Extensions.Configuration and other configuration packages.</PackageDescription>
9-
<PackageReadmeFile>README.md</PackageReadmeFile>
109
</PropertyGroup>
1110

1211
<ItemGroup>
1312
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Primitives\src\Microsoft.Extensions.Primitives.csproj" />
1413
<Compile Include="$(CommonPath)System\ThrowHelper.cs"
1514
Link="Common\System\ThrowHelper.cs" />
16-
<None Include="..\README.md" Pack="true" PackagePath="\"/>
1715
</ItemGroup>
1816

1917
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## About
2+
3+
Provides abstractions of key-value pair based configuration. Interfaces defined in this package are implemented by classes in [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration/) and other configuration packages.
4+
5+
Commonly used types:
6+
7+
- [Microsoft.Extensions.Configuration.IConfiguration](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfiguration)
8+
- [Microsoft.Extensions.Configuration.IConfigurationBuilder](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfigurationbuilder)
9+
- [Microsoft.Extensions.Configuration.IConfigurationProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfigurationprovider)
10+
- [Microsoft.Extensions.Configuration.IConfigurationRoot](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfigurationroot)
11+
- [Microsoft.Extensions.Configuration.IConfigurationSection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfigurationsection)
12+
13+
For more information, see the documentation: [Configuration in .NET](https://learn.microsoft.com/dotnet/core/extensions/configuration).
14+
15+
## Example
16+
17+
The example below shows a small code sample using this library and trying out the `ConfigurationKeyName` attribute available since .NET 6:
18+
19+
```cs
20+
public class MyClass
21+
{
22+
[ConfigurationKeyName("named_property")]
23+
public string NamedProperty { get; set; }
24+
}
25+
```
26+
27+
Given the simple class above, we can create a dictionary to hold the configuration data and use it as the memory source to build a configuration section:
28+
29+
```cs
30+
var dic = new Dictionary<string, string>
31+
{
32+
{"named_property", "value for named property"},
33+
};
34+
35+
var config = new ConfigurationBuilder()
36+
.AddInMemoryCollection(dic)
37+
.Build();
38+
39+
var options = config.Get<MyClass>();
40+
Console.WriteLine(options.NamedProperty); // returns "value for named property"
41+
```

src/libraries/Microsoft.Extensions.Configuration.Binder/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Microsoft.Extensions.Configuration.Binder
22

3-
Provides the functionality to bind an object to data in configuration providers for [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration/). This package enables you to represent the configuration data as strongly-typed classes defined in the application code. To bind a configuration, use the [Microsoft.Extensions.Configuration.ConfigurationBinder.Get](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.configurationbinder.get) extension method on the `IConfiguration` object. To use this package, you also need to install a package for the [configuration provider](https://learn.microsoft.com/dotnet/core/extensions/configuration#configuration-providers), for example, [Microsoft.Extensions.Configuration.Json](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/) for the JSON provider.
3+
Provides the functionality to bind an object to data in configuration providers for [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration/).
44

55
Documentation can be found at https://learn.microsoft.com/dotnet/core/extensions/configuration
66

77
## Contribution Bar
8-
- [x] [We consider new features, new APIs, bug fixes, and performance changes](https://github.com/dotnet/runtime/tree/main/src/libraries#contribution-bar)
8+
- [x] [We consider new features, new APIs, bug fixes, and performance changes](../README.md#contribution-bar)
99

1010
The APIs and functionality are mature, but do get extended occasionally.
1111

src/libraries/Microsoft.Extensions.Configuration.Binder/src/Microsoft.Extensions.Configuration.Binder.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
<IsPackable>true</IsPackable>
77
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
88
<PackageDescription>Provides the functionality to bind an object to data in configuration providers for Microsoft.Extensions.Configuration. This package enables you to represent the configuration data as strongly-typed classes defined in the application code. To bind a configuration, use the Microsoft.Extensions.Configuration.ConfigurationBinder.Get extension method on the IConfiguration object. To use this package, you also need to install a package for the configuration provider, for example, Microsoft.Extensions.Configuration.Json for the JSON provider.</PackageDescription>
9-
<PackageReadmeFile>README.md</PackageReadmeFile>
109
</PropertyGroup>
1110

1211
<ItemGroup>
1312
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Configuration.Abstractions\src\Microsoft.Extensions.Configuration.Abstractions.csproj" />
1413
<Compile Include="$(CommonPath)Extensions\ParameterDefaultValue\ParameterDefaultValue.cs" Link="Common\src\Extensions\ParameterDefaultValue\ParameterDefaultValue.cs" />
1514
<Compile Include="$(CommonPath)System\ThrowHelper.cs" Link="Common\System\ThrowHelper.cs" />
16-
<None Include="..\README.md" Pack="true" PackagePath="\"/>
1715
</ItemGroup>
1816

1917
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## About
2+
3+
Provides the functionality to bind an object to data in configuration providers for [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration/). This package enables you to represent the configuration data as strongly-typed classes defined in the application code. To bind a configuration, use the [Microsoft.Extensions.Configuration.ConfigurationBinder.Get](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.configurationbinder.get) extension method on the `IConfiguration` object. To use this package, you also need to install a package for the [configuration provider](https://learn.microsoft.com/dotnet/core/extensions/configuration#configuration-providers), for example, [Microsoft.Extensions.Configuration.Json](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/) for the JSON provider.
4+
5+
For more information, see the documentation: [Configuration in .NET](https://learn.microsoft.com/dotnet/core/extensions/configuration).
6+
7+
## Example
8+
The following example shows how to bind a JSON configuration section to .NET objects.
9+
10+
```cs
11+
using System;
12+
using Microsoft.Extensions.Configuration;
13+
14+
class Settings
15+
{
16+
public string Server { get; set; }
17+
public string Database { get; set; }
18+
public Endpoint[] Endpoints { get; set; }
19+
}
20+
21+
class Endpoint
22+
{
23+
public string IPAddress { get; set; }
24+
public int Port { get; set; }
25+
}
26+
27+
class Program
28+
{
29+
static void Main()
30+
{
31+
// Build a configuration object from JSON file
32+
IConfiguration config = new ConfigurationBuilder()
33+
.AddJsonFile("appsettings.json")
34+
.Build();
35+
36+
// Bind a configuration section to an instance of Settings class
37+
Settings settings = config.GetSection("Settings").Get<Settings>();
38+
39+
// Read simple values
40+
Console.WriteLine($"Server: {settings.Server}");
41+
Console.WriteLine($"Database: {settings.Database}");
42+
43+
// Read nested objects
44+
Console.WriteLine("Endpoints: ");
45+
46+
foreach (Endpoint endpoint in settings.Endpoints)
47+
{
48+
Console.WriteLine($"{endpoint.IPAddress}:{endpoint.Port}");
49+
}
50+
}
51+
}
52+
```
53+
54+
To run this example, include an `appsettings.json` file with the following content in your project:
55+
56+
```json
57+
{
58+
"Settings": {
59+
"Server": "example.com",
60+
"Database": "Northwind",
61+
"Endpoints": [
62+
{
63+
"IPAddress": "192.168.0.1",
64+
"Port": "80"
65+
},
66+
{
67+
"IPAddress": "192.168.10.1",
68+
"Port": "8080"
69+
}
70+
]
71+
}
72+
}
73+
```
74+
75+
You can include a configuration file using a code like this in your `.csproj` file:
76+
77+
```xml
78+
<ItemGroup>
79+
<Content Include="appsettings.json">
80+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
81+
</Content>
82+
</ItemGroup>
83+
```

src/libraries/Microsoft.Extensions.Configuration.CommandLine/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Microsoft.Extensions.Configuration.CommandLine
22

3-
Command line configuration provider implementation for [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration/). This package enables you to read configuration parameters from the command line arguments of your application. You can use [CommandLineConfigurationExtensions.AddCommandLine](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.commandlineconfigurationextensions.addcommandline) extension method on `IConfigurationBuilder` to add the command line configuration provider to the configuration builder.
3+
Command line configuration provider implementation for [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration/).
44

55
Documentation can be found at https://learn.microsoft.com/dotnet/core/extensions/configuration-providers#command-line-configuration-provider
66

77
## Contribution Bar
8-
- [x] [We consider new features, new APIs, bug fixes, and performance changes](https://github.com/dotnet/runtime/tree/main/src/libraries#contribution-bar)
8+
- [x] [We consider new features, new APIs, bug fixes, and performance changes](../README.md#contribution-bar)
99

1010
The APIs and functionality are mature, but do get extended occasionally.
1111

src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
<IsPackable>true</IsPackable>
77
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
88
<PackageDescription>Command line configuration provider implementation for Microsoft.Extensions.Configuration. This package enables you to read configuration parameters from the command line arguments of your application. You can use CommandLineConfigurationExtensions.AddCommandLine extension method on IConfigurationBuilder to add the command line configuration provider to the configuration builder.</PackageDescription>
9-
<PackageReadmeFile>README.md</PackageReadmeFile>
109
</PropertyGroup>
1110

1211
<ItemGroup>
1312
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Configuration\src\Microsoft.Extensions.Configuration.csproj" />
1413
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Configuration.Abstractions\src\Microsoft.Extensions.Configuration.Abstractions.csproj" />
1514
<Compile Include="$(CommonPath)System\ThrowHelper.cs"
1615
Link="Common\System\ThrowHelper.cs" />
17-
<None Include="..\README.md" Pack="true" PackagePath="\"/>
1816
</ItemGroup>
1917

2018
</Project>

0 commit comments

Comments
 (0)