Gnar.Enver.InMemory 1.0.0

dotnet add package Gnar.Enver.InMemory --version 1.0.0
                    
NuGet\Install-Package Gnar.Enver.InMemory -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.InMemory" 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.InMemory" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Gnar.Enver.InMemory" />
                    
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.InMemory --version 1.0.0
                    
#r "nuget: Gnar.Enver.InMemory, 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.InMemory@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.InMemory&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Gnar.Enver.InMemory&version=1.0.0
                    
Install as a Cake Tool

Enver.InMemory

Load .env files into an in-memory dictionary with platform-appropriate key comparison (case-insensitive on Windows, case-sensitive on Unix).

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

Quick start

dotnet add package Gnar.Enver.InMemory
using Enver;

// Reads .env from the executable's directory.
var values = EnvCollection.From(DotEnvPaths.AppDirectory());

string dbHost = values.GetString("DB_HOST");
int    port   = values.GetInt32("DB_PORT");

// EnvCollection is a Dictionary. Use it however you'd use one.
foreach (var (key, value) in values)
{
    Console.WriteLine($"{key} = {value}");
}

Typed accessors

EnvCollection implements IEnvReader, so all typed accessors (Get* / Get*(key, default) / GetOptional* / TryGet*) apply directly:

using System.Net;
using Enver;

var values = EnvCollection.From(DotEnvPaths.AppDirectory());

string dbHost    = values.GetString("DB_HOST");
int    port      = values.GetInt32("DB_PORT", 5432);    // default if missing; 0x/0b prefixes supported
bool   debug     = values.GetBoolean("DEBUG", false);   // default if missing; strict true/false
Uri    apiUrl    = values.GetUri("API_URL");
IPAddress bindIp = values.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

EnvCollection.From has two shapes:

// Single file. Missing files are silent.
EnvCollection.From("/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.
EnvCollection.From([file1, file2]);
EnvCollection.From(DotEnvPaths.AppDirectory());                          // .env in app dir
EnvCollection.From(DotEnvPaths.WorkingDirectory().Standard("dev"));      // 4-tier ladder
EnvCollection.From(DotEnvPaths.AppDirectory().WithParentDirectories(int.MaxValue)); // walk to root

// Async variants:
await EnvCollection.FromAsync("/etc/myapp/.env");
await EnvCollection.FromAsync(DotEnvPaths.AppDirectory().Standard("dev"));

Missing files are silently skipped. Callers needing strict "this file must exist" semantics should check with File.Exists before calling.

Composing paths with DotEnvPaths

DotEnvPaths is a composable builder for the canonical .env load ladder. The canonical precedence is fixed:

.env < .env.{variant} < .env.local < .env.{variant}.local

// Roots
DotEnvPaths.AppDirectory()         // AppContext.BaseDirectory
DotEnvPaths.WorkingDirectory()     // Directory.GetCurrentDirectory() at load time
DotEnvPaths.Directory("/var/app")  // explicit
DotEnvPaths.Relative()             // bare filenames; resolution deferred to consumer

// Modifiers
.WithFileName("config.env")        // base filename (defaults to ".env")
.WithVariant("dev")                // adds .env.{variant} tier
.WithLocal()                       // adds .env.local (+ .env.{variant}.local if variant set)
.WithParentDirectories(2)          // walks ancestors (base + variant only; local stays at start; not supported on Relative)
.Standard("dev")                   // equivalent to .WithVariant("dev").WithLocal()

A builder implements IEnumerable<string>, so it composes directly into collection-expression spreads:

EnvCollection.From([
    .. DotEnvPaths.AppDirectory().Standard("dev"),
    "/etc/myapp/overrides.env",
]);

Duplicate-key handling

Within a single file, defining the same key twice throws by default:

// Throws EnvDuplicateKeyException: "Duplicate key 'DB_HOST' encountered in input."
var coll = new EnvCollection();
new EnvDictionaryParser(coll).Parse("DB_HOST=a\nDB_HOST=b");

To allow duplicates within a file:

EnvCollection.From(
    DotEnvPaths.AppDirectory(),
    parseOptions: new EnvParseOptions { AllowDuplicateKeys = true });

Across files in a single load (e.g. .env then .env.local), values are intentionally overridden. Files later in the path list override earlier ones. Combined with DotEnvPaths.WithParentDirectories, files in closer directories override files in farther ancestors.

For example:

EnvCollection.From(DotEnvPaths.AppDirectory().Standard().WithParentDirectories(1));

with these files:

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

will produce KEY=app root + local.

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 (1)

Showing the top 1 NuGet packages that depend on Gnar.Enver.InMemory:

Package Downloads
Gnar.Enver.Extensions.Configuration

Microsoft.Extensions.Configuration integration for Enver. Provides AddDotEnvFiles for IConfigurationBuilder and AsEnvReader for typed access over any IConfiguration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 132 5/30/2026
0.1.0-beta.4 55 5/23/2026
0.1.0-beta.3 56 5/18/2026
0.1.0-beta.2 57 5/18/2026
0.0.0-alpha.0.23 54 5/18/2026
0.0.0-alpha.0.21 54 5/18/2026