CS.EnvConfig 0.0.3

dotnet add package CS.EnvConfig --version 0.0.3
                    
NuGet\Install-Package CS.EnvConfig -Version 0.0.3
                    
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="CS.EnvConfig" Version="0.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CS.EnvConfig" Version="0.0.3" />
                    
Directory.Packages.props
<PackageReference Include="CS.EnvConfig" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CS.EnvConfig --version 0.0.3
                    
#r "nuget: CS.EnvConfig, 0.0.3"
                    
#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.
#:package CS.EnvConfig@0.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CS.EnvConfig&version=0.0.3
                    
Install as a Cake Addin
#tool nuget:?package=CS.EnvConfig&version=0.0.3
                    
Install as a Cake Tool

EnvConfig

EnvConfig is a lightweight library that simplifies retrieving configuration values from environment variables. It uses attributes to map environment variables onto class properties, offering convenient defaults for each property type.

Installation

# Install the latest version from NuGet
dotnet add package CS.EnvConfig
# Install the specific version
dotnet add package CS.EnvConfig --version 0.0.2

Usage

  1. Create a configuration class with properties annotated using [EnvVar].
  2. Use EnvConfigLoader.Load<YourConfig>() to populate those properties from environment variables if available; otherwise default values are used.

Example:

public class MyConfig
{
    [EnvVar("API_ENDPOINT", "https://default.api")]
    public string? API_ENDPOINT { get; set; }

    [EnvVar("RETRY_COUNT", 3)]
    public int? RETRY_COUNT { get; set; }

    [EnvVar("MY_BOOL", true)]
    public bool? MY_BOOL { get; set; }

    [EnvVar("MY_BOOL_2", false)]
    public bool? MY_BOOL_2 { get; set; }

    [EnvVar("MY_DOUBLE", 0.123)]
    public double? MY_DOUBLE { get; set; }
}


public class Program
{
    public static void Main()
    {
        var config = EnvConfigLoader.Load<MyConfig>();
        Console.WriteLine($"API_ENDPOINT: {config.API_ENDPOINT}");
        Console.WriteLine($"RETRY_COUNT: {config.RETRY_COUNT}");
    }
}

See the example app for a complete example of how to use the library, or the test cases in the EnvConfig/EnvConfig_test.cs.

TODO

  • Create a pipeline to publish new version to public NuGet.

Contributing

Feel free to open pull requests or issues to improve the library. You’re welcome to suggest enhancements, report bugs, or contribute documentation.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
0.0.3 207 5/1/2025
0.0.2 193 5/1/2025
0.0.1 187 5/1/2025