Enver.SystemEnvironment
0.0.0-alpha.0.19
dotnet add package Enver.SystemEnvironment --version 0.0.0-alpha.0.19
NuGet\Install-Package Enver.SystemEnvironment -Version 0.0.0-alpha.0.19
<PackageReference Include="Enver.SystemEnvironment" Version="0.0.0-alpha.0.19" />
<PackageVersion Include="Enver.SystemEnvironment" Version="0.0.0-alpha.0.19" />
<PackageReference Include="Enver.SystemEnvironment" />
paket add Enver.SystemEnvironment --version 0.0.0-alpha.0.19
#r "nuget: Enver.SystemEnvironment, 0.0.0-alpha.0.19"
#:package Enver.SystemEnvironment@0.0.0-alpha.0.19
#addin nuget:?package=Enver.SystemEnvironment&version=0.0.0-alpha.0.19&prerelease
#tool nuget:?package=Enver.SystemEnvironment&version=0.0.0-alpha.0.19&prerelease
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
using Enver;
// Reads .env from the executable's directory and writes each entry to the
// process environment.
// C# 14+ only
Environment.LoadDotEnvFromAppDirectory();
// OR
EnvironmentExtensions.LoadDotEnvFromAppDirectory();
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): throwsEnverExceptionon 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.
Loader variants
// Load a specific file. Throws if missing.
Environment.LoadDotEnv("/etc/myapp/.env");
// Load .env files from the current working directory rather than the app directory.
Environment.LoadDotEnvFromWorkingDirectory();
// Load .env file from a specific directory.
Environment.LoadDotEnvFromDirectory("/var/myapp");
// Walk up all parent directories; closer files override farther ones.
Environment.LoadDotEnvFromAppDirectory(maxAncestors: int.MaxValue);
// .env then .env.production in the app directory.
Environment.LoadDotEnvFromAppDirectory(variant: "production");
// Async variants for all of the above.
await Environment.LoadDotEnvFromAppDirectoryAsync();
Cross-file precedence
Across files in a single load (e.g. .env then .env.production), values are
intentionally overridden. Files closer to the source directory override farther
files, and variants override the base file.
For example, parsing with:
Environment.LoadDotEnvFromAppDirectory(variant: "production", maxAncestors: 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.LoadDotEnvFromAppDirectory(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. |
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 |
|---|