Microsoft.Extensions.Configuration 10.0.12

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Microsoft.Extensions.Configuration --version 10.0.12
                    
NuGet\Install-Package Microsoft.Extensions.Configuration -Version 10.0.12
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="10.0.12" />
                    
Directory.Packages.props
<PackageReference Include="Microsoft.Extensions.Configuration" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Microsoft.Extensions.Configuration --version 10.0.12
                    
#r "nuget: Microsoft.Extensions.Configuration, 10.0.12"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Microsoft.Extensions.Configuration@10.0.12
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Microsoft.Extensions.Configuration&version=10.0.12
                    
Install as a Cake Addin
#tool nuget:?package=Microsoft.Extensions.Configuration&version=10.0.12
                    
Install as a Cake Tool

About

Microsoft.Extensions.Configuration is combined with a core configuration abstraction under Microsoft.Extensions.Configuration.Abstractions that allows for building different kinds of configuration providers to retrieve key/value pair configuration values from in the form of IConfiguration. There are a number of built-in configuration provider implementations to read from environment variables, in-memory collections, JSON, INI or XML files. Aside from the built-in variations, there are more shipped libraries shipped by community for integration with various configuration service and other data sources.

Key Features

  • In-memory configuration provider
  • Chained configuration provider for chaining multiple confiugration providers together.
  • Base types that implement configuration abstraction interfaces that can be used when implementing other configuration providers.

How to Use

using Microsoft.Extensions.Configuration;

var configurationBuilder = new ConfigurationBuilder();

configurationBuilder.AddInMemoryCollection(
    new Dictionary<string, string?>
    {
        ["Setting1"] = "value",
        ["MyOptions:Enabled"] = bool.TrueString,
    });

configurationBuilder.AddInMemoryCollection(
    new Dictionary<string, string?>
    {
        ["Setting2"] = "value2",
        ["MyOptions:Enabled"] = bool.FalseString,
    });

var config = configurationBuilder.Build();

// note case-insensitive
Console.WriteLine(config["setting1"]);
Console.WriteLine(config["setting2"]);

// note last in wins
Console.WriteLine(config["MyOptions:Enabled"]);

Main Types

The main types provided by this library are:

  • Microsoft.Extensions.Configuration.ConfigurationBuilder
  • Microsoft.Extensions.Configuration.ConfigurationManager
  • Microsoft.Extensions.Configuration.ConfigurationRoot
  • Microsoft.Extensions.Configuration.ConfigurationSection

Additional Documentation