dotnet add package ConsoleConfigurationLibrary --version
NuGet\Install-Package ConsoleConfigurationLibrary -Version
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="ConsoleConfigurationLibrary" Version="" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ConsoleConfigurationLibrary --version
#r "nuget: ConsoleConfigurationLibrary,"
#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 ConsoleConfigurationLibrary as a Cake Addin
#addin nuget:?package=ConsoleConfigurationLibrary&version=

// Install ConsoleConfigurationLibrary as a Cake Tool
#tool nuget:?package=ConsoleConfigurationLibrary&version=


Blue Injection64 64

Provides easy access to connection strings in a Console project's appsettings.json file.


With the following appsettings.json file

  "ConnectionStrings": {
    "MainConnection": "Data Source=.\\SQLEXPRESS;Initial Catalog=Chinook;Integrated Security=True;Encrypt=False",
    "SecondaryConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=NorthWind2024;Integrated Security=True;Encrypt=False",
    "OtherConnection": "Other"

Add this package to a console project then in Program.cs, call RegisterConnectionServices.Configure()

static async Task Main(string[] args)

    await RegisterConnectionServices.Configure();

To access the MainConnectionString use AppConnections.Instance.MainConnection as shown below, in this case using Dapper.

public static List<Track> TrackList(int albumId)
    using SqlConnection cn = new(AppConnections.Instance.MainConnection);
    return cn.Query<Track>(SqlStatements.TracksByAlbumId, new { AlbumId = albumId }).ToList();

Then for the second connection string

public static List<Categories> CategoryList()
    using SqlConnection cn = new(AppConnections.Instance.SecondaryConnection);
    return cn.Query<Categories>(SqlStatements.Categories).ToList();

And Other connection string follows the same as both of the above.

Working code samples

See the project ConsoleConfigurationApp.

  • Run the scripts under the script folder before run the project.

Release notes

  • 04/26/2024 no functionality change, simple refactor.
Product Compatible and additional computed target framework versions.
.NET 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. 
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 126 5/4/2024 98 4/26/2024
1.0.0 182 12/23/2023

Initial release