Conphig 2.0.1
dotnet add package Conphig --version 2.0.1
NuGet\Install-Package Conphig -Version 2.0.1
<PackageReference Include="Conphig" Version="2.0.1" />
paket add Conphig --version 2.0.1
#r "nuget: Conphig, 2.0.1"
// Install Conphig as a Cake Addin
#addin nuget:?package=Conphig&version=2.0.1
// Install Conphig as a Cake Tool
#tool nuget:?package=Conphig&version=2.0.1
conphig
Conphig is a .NET 6 package for loading configuration from JSON files, command line and environment variables.
Getting started
After installing the Conphig
package, create a simple POCO class and place your configuration items as properties inside.
For each property, use the JsonPropertyName
, CommandLine
, and EnvironmentVariable
attributes to control how that property is deserialized from JSON files, command line parameters, and environment variables.
Then, in your Main
method (or somewhere else that makes sense given your app startup code), add a call to Config.Load<T>
to create and populate an object containing your configuration items.
Example configuration class
using System.Text.Json.Serialization;
using ATornblad.Conphig;
namespace MyApp
{
[Filename("app-configuration.json")]
public class Settings
{
[JsonPropertyName("title")]
[EnvironmentVariable("TITLE")]
[CommandLine("-t", "--title")]
public string Title { get; set; } = "Untitled";
[JsonPropertyName("Categories")]
[CommandLine("-c", "--category")]
public string[] Categories { get; set; }
[EnvironmentVariable("API_KEY")]
public string ApiKey { get; set; }
[CommandLine("-v", "--verbose")]
public bool VerboseOutput { get; set; }
}
}
Example of loading
using System;
using ATornblad.Conphig;
namespace MyApp
{
public class Program
{
public static void Main(string[] args)
{
var settings = Config.Load<Settings>();
if (settings.VerboseOutput)
{
Console.WriteLine($"Title: {settings.Title}");
}
}
}
}
Example of configuration file
{
"title": "Title from JSON file",
"categories": [
"API",
"Programming",
"C#"
]
}
Example of command line arguments
myapp --verbose -t "Title from Command Line" -c API -c Programming -c bash
Read more
For more information, visit the Project Website
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 was computed. net8.0-android 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.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v2.0.1 : Small performance improvement in array parsing, and code clean-up
v2.0.0 : DefaultAttribute made obsolete
v1.0.3 : Ported to .NET 6.0
v1.0.2 : Minor bug fixes
v1.0.1 : Minor bug fixes
v1.0.0 : First major release. DefaultAttribute is made obsolete.
v0.9.3 : Minor bug fixes
v0.9.2 : Added better package documentation
v0.9.1 : Added support for array properties
v0.9.0 : First release