Gnar.Enver.SystemEnvironment 1.0.0

dotnet add package Gnar.Enver.SystemEnvironment --version 1.0.0
                    
NuGet\Install-Package Gnar.Enver.SystemEnvironment -Version 1.0.0
                    
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="Gnar.Enver.SystemEnvironment" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Gnar.Enver.SystemEnvironment" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Gnar.Enver.SystemEnvironment" />
                    
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 Gnar.Enver.SystemEnvironment --version 1.0.0
                    
#r "nuget: Gnar.Enver.SystemEnvironment, 1.0.0"
                    
#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 Gnar.Enver.SystemEnvironment@1.0.0
                    
#: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=Gnar.Enver.SystemEnvironment&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Gnar.Enver.SystemEnvironment&version=1.0.0
                    
Install as a Cake Tool

Enver.SystemEnvironment

Load .env files into the process environment block via Environment.SetEnvironmentVariable. Useful when downstream code already reads from Environment.GetEnvironmentVariable(...) and you want .env files to participate in that lookup without changing the consuming code.

Part of the Enver family. See the main project README for the broader ecosystem.

Quick start

dotnet add package Gnar.Enver.SystemEnvironment
using Enver;

// Reads .env from the executable's directory and writes each entry to the
// process environment.
// C# 14+ only
Environment.LoadDotEnv(DotEnvPaths.AppDirectory());
// OR
EnvironmentExtensions.LoadDotEnv(DotEnvPaths.AppDirectory());

var dbHost = Environment.GetEnvironmentVariable("DB_HOST");

Typed accessors

Environment.Variables is a zero-cost IEnvReader over the process env block, so the full typed accessor surface (Get* / Get*(key, default) / GetOptional* / TryGet*) applies directly:

using System.Net;
using Enver;

string dbHost    = Environment.Variables.GetString("DB_HOST");
int    port      = Environment.Variables.GetInt32("DB_PORT", 5432);    // default if missing; 0x/0b prefixes supported
bool   debug     = Environment.Variables.GetBoolean("DEBUG", false);   // default if missing; strict true/false
Uri    apiUrl    = Environment.Variables.GetUri("API_URL");
IPAddress bindIp = Environment.Variables.Get<IPAddress>("BIND_ADDRESS");

The four patterns:

  • Get*(key): throws EnvException on missing or unparseable.
  • Get*(key, default): returns default on missing; throws on unparseable.
  • GetOptional*(key): returns null on missing; throws on unparseable.
  • TryGet*(key, out value): returns false on missing or unparseable.

See the main project README for the full list of supported types.

Loading

Environment.LoadDotEnv has two shapes:

// Single file. Missing files are silent.
Environment.LoadDotEnv("/etc/myapp/.env");

// Path list. Files load in order; later files override earlier ones, with
// shared ${VAR} interpolation across the whole sequence. Pair with
// DotEnvPaths to compose the canonical ladder.
Environment.LoadDotEnv([file1, file2]);
Environment.LoadDotEnv(DotEnvPaths.AppDirectory());                          // .env in app dir
Environment.LoadDotEnv(DotEnvPaths.WorkingDirectory().Standard("production")); // 4-tier ladder
Environment.LoadDotEnv(DotEnvPaths.AppDirectory().WithParentDirectories(int.MaxValue)); // walk to root

// Async variants:
await Environment.LoadDotEnvAsync("/etc/myapp/.env");
await Environment.LoadDotEnvAsync(DotEnvPaths.AppDirectory().Standard("production"));

Missing files are silently skipped. See the DotEnvPaths reference in Enver.InMemory's README for the full builder surface.

Cross-file precedence

Across files in a single load (e.g. .env then .env.production), values are intentionally overridden. Files later in the path list override earlier ones.

For example:

Environment.LoadDotEnv(
    DotEnvPaths.AppDirectory().WithVariant("production").WithParentDirectories(1));

with these files:

/path/to/your/app/.env.production -> KEY=app root + production
/path/to/your/app/.env            -> KEY=app root
/path/to/your/.env.production     -> KEY=parent dir + production
/path/to/your/.env                -> KEY=parent dir

will produce KEY=app root + production.

Existing env vars

By default, .env entries are skipped if the variable is already set in the process environment.

To make the .env file authoritative, pass overrideExisting: true:

Environment.LoadDotEnv(DotEnvPaths.AppDirectory(), overrideExisting: true);

License

MIT.

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 is compatible.  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 is compatible.  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
1.0.0 95 5/30/2026
0.1.0-beta.4 51 5/23/2026
0.1.0-beta.3 63 5/18/2026
0.1.0-beta.2 54 5/18/2026
0.0.0-alpha.0.23 48 5/18/2026
0.0.0-alpha.0.21 47 5/18/2026