Conphig 2.1.1

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

// Install Conphig as a Cake Tool
#tool nuget:?package=Conphig&version=2.1.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; }

        [JsonPropertyName("permissions")]
        [CommandLine("-p", "--permissions")]
        public PermissionLevels Permissions { get; set; } = PermissionLevels.None;
    }

    [Flags]
    public enum PermissionLevels
    {
        None = 0,
        Create = 1,
        Read = 2,
        Edit = 4,
        Delete = 8
    }
}

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#"
    ],
    "permissions": "Create,Read,Edit"
}

Example of command line arguments

myapp --verbose -t "Title from Command Line" -c API -c Programming -c bash -p Read,Edit

Read more

For more information, visit the Project Website

Product 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-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.
  • 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.

Version Downloads Last updated
2.1.1 244 1/23/2024
2.1.0 82 1/23/2024
2.0.1 366 1/13/2023
2.0.0 259 1/12/2023
1.0.2 773 10/12/2021
1.0.1 639 10/6/2021
1.0.0 296 10/5/2021
0.9.3 310 10/1/2021
0.9.2 291 10/1/2021
0.9.1 346 9/30/2021
0.9.0 283 9/30/2021

v2.1.1 : Added support for enum types
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