src/libraries/Microsoft.Extensions.Configuration.Ini/README.md
INI configuration provider implementation for Microsoft.Extensions.Configuration.
Documentation can be found at https://learn.microsoft.com/dotnet/core/extensions/configuration-providers#ini-configuration-provider
The APIs and functionality are mature, but do get extended occasionally.
Microsoft.Extensions.Configuration.Ini is included in the ASP.NET Core shared framework. The package is deployed as out-of-band (OOB) too and can be referenced into projects directly.
The following example shows how to read the application configuration from INI file.
using System;
using Microsoft.Extensions.Configuration;
class Program
{
static void Main()
{
// Build a configuration object from INI file
IConfiguration config = new ConfigurationBuilder()
.AddIniFile("appsettings.ini")
.Build();
// Get a configuration section
IConfigurationSection section = config.GetSection("Settings");
// Read configuration values
Console.WriteLine($"Server: {section["Server"]}");
Console.WriteLine($"Database: {section["Database"]}");
}
}
To run this example, include an appsettings.ini file with the following content in your project:
[Settings]
Server=example.com
Database=Northwind
You can include a configuration file using a code like this in your .csproj file:
<ItemGroup>
<Content Include="appsettings.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>