Enver.SystemEnvironment 0.0.0-alpha.0.19

This is a prerelease version of Enver.SystemEnvironment.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Enver.SystemEnvironment --version 0.0.0-alpha.0.19
                    
NuGet\Install-Package Enver.SystemEnvironment -Version 0.0.0-alpha.0.19
                    
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="Enver.SystemEnvironment" Version="0.0.0-alpha.0.19" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Enver.SystemEnvironment" Version="0.0.0-alpha.0.19" />
                    
Directory.Packages.props
<PackageReference Include="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 Enver.SystemEnvironment --version 0.0.0-alpha.0.19
                    
#r "nuget: Enver.SystemEnvironment, 0.0.0-alpha.0.19"
                    
#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 Enver.SystemEnvironment@0.0.0-alpha.0.19
                    
#: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=Enver.SystemEnvironment&version=0.0.0-alpha.0.19&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Enver.SystemEnvironment&version=0.0.0-alpha.0.19&prerelease
                    
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

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): throws EnverException 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.

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 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.
  • net10.0

    • Enver (>= 0.0.0-alpha.0.19)
  • net8.0

    • Enver (>= 0.0.0-alpha.0.19)
  • net9.0

    • Enver (>= 0.0.0-alpha.0.19)

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