Conphig 1.0.2

.NET 5.0
dotnet add package Conphig --version 1.0.2
NuGet\Install-Package Conphig -Version 1.0.2
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="Conphig" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Conphig --version 1.0.2
#r "nuget: Conphig, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Conphig as a Cake Addin
#addin nuget:?package=Conphig&version=1.0.2

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

conphig

Conphig is a .NET 5 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
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • net5.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.

Version Downloads Last updated
1.0.2 439 10/12/2021
1.0.1 545 10/6/2021
1.0.0 200 10/5/2021
0.9.3 201 10/1/2021
0.9.2 194 10/1/2021
0.9.1 249 9/30/2021
0.9.0 185 9/30/2021

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