NetLah.Extensions.Configuration 1.0.0-rc3.3

Prefix Reserved
This is a prerelease version of NetLah.Extensions.Configuration.
dotnet add package NetLah.Extensions.Configuration --version 1.0.0-rc3.3                
NuGet\Install-Package NetLah.Extensions.Configuration -Version 1.0.0-rc3.3                
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="NetLah.Extensions.Configuration" Version="1.0.0-rc3.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetLah.Extensions.Configuration --version 1.0.0-rc3.3                
#r "nuget: NetLah.Extensions.Configuration, 1.0.0-rc3.3"                
#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.
// Install NetLah.Extensions.Configuration as a Cake Addin
#addin nuget:?package=NetLah.Extensions.Configuration&version=1.0.0-rc3.3&prerelease

// Install NetLah.Extensions.Configuration as a Cake Tool
#tool nuget:?package=NetLah.Extensions.Configuration&version=1.0.0-rc3.3&prerelease                

NetLah.Extensions.Configuration - .NET Library

NetLah.Extensions.Configuration is a library which contains a set of reusable classes for build configuration with environment. These library classes are ConfigurationBuilderBuilder, CertificateLoader and ConnectionStringManager.

Nuget package


Build Status

Build Status

Getting started


public static void Main(string[] args)
    var configuration = ConfigurationBuilderBuilder.Create<Program>(args).Build();
    var defaultConnectionString = configuration.GetConnectionString("DefaultConnection");
    Console.WriteLine($"[TRACE] ConnectionString: {defaultConnectionString}");

Full API support

var initConfig = new ConfigurationBuilder().Build();
IConfigurationRoot configuration = new ConfigurationBuilderBuilder()
    .WithInMemory(new Dictionary<string, string?>{ ["Key:Sub"] = "Value" })
    .WithAddConfiguration(cb => cb.AddIniFile("appsettings.ini", optional: true, reloadOnChange: true))

Order of Precedence when Configuring

  • Reference

  • Order of Precedence
  1. Host configuration from environment variables by prefix DOTNET_ and ASPNETCORE_
  2. Chanined configuration (if any)
  3. In memory configuration (if any)
  4. appsettings.json using the JSON configuration provider
  5. appsettings.EnvironmentName.json using the JSON configuration provider
  6. Other extra configuration sources
  7. App secrets when the app runs in the Development environment
  8. Environment variables using the Environment Variables configuration provider
  9. Command-line arguments using the Command-line configuration provider

BasePath of configuration files

The application binary folder is default basePath for appsettings.json, appsettings.Production.json,etc. In case want to change current directory as basePath:

var configuration = new ConfigurationBuilderBuilder()

Environment name

Production environmentName by default if no host environmentName configuration

ConfigurationBuilderBuilder will detect EnvironmentName by add configuration environment variables with prefix DOTNET_ and ASPNETCORE_. If no environment variable set, Production will use by default. Example of environment variables:


Specifying environmentName during build configuration

Sometime, we cannot set the environmentName using environment variable, or we need different environment configuration build lik in unit test project, we can specific the environmentName.

var configuration = ConfigurationBuilderBuilder.Create<ConfigurationBuilderBuilderTest>()

Add extra configuration sources

var configuration = ConfigurationBuilderBuilder.Create<Program>()
    .WithAddConfiguration(cb => cb.AddIniFile("appsettings.ini", optional: true, reloadOnChange: true))
    .WithAddConfiguration(cb => cb.AddXmlFile("appsettings.xml", optional: true, reloadOnChange: true))


var configuration = ConfigurationBuilderBuilder.Create<Program>()
        cb => cb.AddIniFile("appsettings.ini", optional: true, reloadOnChange: true)
            .AddXmlFile("appsettings.xml", optional: true, reloadOnChange: true)

ConnectionStringManager load from Configuration with database provider information

Reference at

Support provider

public enum DbProviders

List of supported provider name




Configuration appsettings.json or environment

  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Database=dbname;Integrated Security=True;",
    "DefaultConnection_ProviderName": "System.Data.SqlClient",
    "BlogConnection": "AccountEndpoint=;",
    "BlogConnection_ProviderName": "Cosmos1",
    "BlogConnection2_Cosmos": "AccountEndpoint=;"

Basic usage:

IConfiguration configuration;
var connStrManager = new ConnectionStringManager(configuration);
var conn = connStrManager["defaultConnection"];
if (conn != null) {
    if (conn.Provider == DbProviders.PostgreSQL) {
    } else if (conn.Provider == DbProviders.MySQL) {
    } else if (conn.Provider == DbProviders.SQLServer) {
    } else if (conn.Provider == DbProviders.Custom && conn.Custom == "Cosmos1") {

Multi connectionNames:

var conn = connStrManager["BlogConnection", "BlogConnection2"];
if (conn != null) {
    if (conn.Provider == DbProviders.Custom && conn.Custom == "Cosmos1") {
    } else if (conn.Provider == DbProviders.Custom && conn.Custom == "Cosmos") {

Troubleshooting appsettings, configuration and connection strings

Use docker for troubleshooting

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-rc3.3 133 5/30/2024
1.0.0-rc3.2 69 5/14/2024
1.0.0-rc3.1 52 5/13/2024
1.0.0-rc2 133 3/21/2024
1.0.0-rc1 399 1/12/2024
0.2.2 1,141 1/1/2023
0.2.2-rc1 746 9/14/2022
0.2.1 1,309 11/19/2021
0.2.0 895 11/11/2021
0.2.0-rc2 36,528 10/18/2021
0.2.0-rc1.5 46,642 9/29/2021
0.2.0-rc1.1 13,157 9/16/2021
0.1.7 82,473 8/25/2021
0.1.6 968 8/24/2021
0.1.5 764 8/20/2021
0.1.4 740 8/18/2021
0.1.3 780 8/17/2021
0.1.2 857 8/14/2021
0.1.1 1,399 6/7/2021
0.1.0 944 5/11/2021