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
<PackageReference Include="Gnar.Enver.SystemEnvironment" Version="1.0.0" />
<PackageVersion Include="Gnar.Enver.SystemEnvironment" Version="1.0.0" />
<PackageReference Include="Gnar.Enver.SystemEnvironment" />
paket add Gnar.Enver.SystemEnvironment --version 1.0.0
#r "nuget: Gnar.Enver.SystemEnvironment, 1.0.0"
#:package Gnar.Enver.SystemEnvironment@1.0.0
#addin nuget:?package=Gnar.Enver.SystemEnvironment&version=1.0.0
#tool nuget:?package=Gnar.Enver.SystemEnvironment&version=1.0.0
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): throwsEnvExceptionon missing or unparseable.Get*(key, default): returnsdefaulton missing; throws on unparseable.GetOptional*(key): returnsnullon missing; throws on unparseable.TryGet*(key, out value): returnsfalseon 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 | Versions 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. |
-
net10.0
- Gnar.Enver (>= 1.0.0)
-
net8.0
- Gnar.Enver (>= 1.0.0)
-
net9.0
- Gnar.Enver (>= 1.0.0)
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 |