kdheath.Configuration.Helper
2.0.4
Prefix Reserved
See the version list below for details.
dotnet add package kdheath.Configuration.Helper --version 2.0.4
NuGet\Install-Package kdheath.Configuration.Helper -Version 2.0.4
<PackageReference Include="kdheath.Configuration.Helper" Version="2.0.4" />
paket add kdheath.Configuration.Helper --version 2.0.4
#r "nuget: kdheath.Configuration.Helper, 2.0.4"
// Install kdheath.Configuration.Helper as a Cake Addin #addin nuget:?package=kdheath.Configuration.Helper&version=2.0.4 // Install kdheath.Configuration.Helper as a Cake Tool #tool nuget:?package=kdheath.Configuration.Helper&version=2.0.4
About
The Configuration.Helper package is a light-weight platform for .NET to support application settings in old-style App.config files, and as of version 1.0.1, the newer style of JSON files.
See Change Log for all release notes.
Main Types
ConfigFileHelper
- Helper class for Configuration file access.IOHelper
- Helper class forSystem.IO
operations.WebConnectionStringBuilder
- Provides a simple way to create and manage the contents of connection strings used for a Microsoft Dataverse connection.
See .NET Helper Packages for technical documentation.
How to Use
- The naming of the standard sections
AppSettings
andConnectionStrings
along with any custom sections are case insensitive. - All the values must be defined as strings.
A JSON style configuration file would look like:
{
"appSettings": {
"FavoriteMovie": "Dune",
"FavoriteDirector": "James Cameron",
"FavoriteActor": "Johnny Depp"
},
"connectionStrings": {
"Movies": "DataSource=localhost;Initial Catalog=MovieCatalog;Integrated Security=True"
},
"Custom": {
"Password": "abc123"
}
}
The older style XML application settings file would look like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="FavouriteMovie" value="Dune" />
<add key="FavouriteDirector" value="James Cameron" />
<add key="FavouriteActor" value="Johnny Depp" />
</appSettings>
<connectionStrings>
<clear />
<add name="Movies" connectionString="DataSource=localhost;Initial Catalog=MovieCatalog;Integrated Security=True" />
</connectionStrings>
<Custom>
<add key="Password" value="abc123" />
</Custom>
</configuration>
To access the settings from C# code:
using Configuration.Helper;
// Load the configuration settings
var config = ConfigFileHelper.GetConfiguration( "appSettings.json" );
// Get a setting value from the AppSettings section
var director = config.GetSetting( "favoritedirector" );
// Get a setting value from the ConnectionStrings section
var connect = config.ConnectionStrings.GetSetting( "movies" );
// Get a setting value from the Custom section
var password = config.GetSection( "custom" ).GetSetting( "password" );
// Add or update a setting value in the AppSettings section
var ok = config.AddSetting( "FavouriteActress", "Julia Roberts" );
ok = config.AddSetting( @"favouriteactress", "Angelina Jolie" );
Feedback
This is provided as open source under the MIT license.
Bug reports and contributions are welcome in the GitHub repository.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. |
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
* Added package tags.