$ show bolorundurowb/dotenv.net
dotenv.net is a lightweight .NET library for loading environment variables from .env files. It provides both a static API (DotEnv.Load, DotEnv.Read) and a fluent builder (DotEnv.Fluent) for configuring options such as file paths, encoding, trimming, overwrite behavior, directory probing, export syntax support, inline comment stripping, and variable expansion/interpolation. The library supports hierarchical environment cascade loading (e.g., .env, .env.local, .env.{Environment}) and integrates with Microsoft.Extensions.Configuration via a separate package (dotenv.net.Configuration). Internally, it consists of a parser that handles single/double quoted values, multi-line values, and escape sequences; a variable expander that resolves ${VAR}, $VAR, and default fallback syntax with circular dependency detection; and a reader that reads from files or streams, probes parent directories, and merges key-value pairs. The codebase is well-structured with comprehensive unit tests covering edge cases, and targets netstandard2.0/2.1 for broad compatibility.
The LLM identified 2 files worth highlighting for reuse:
Implements a recursive variable expansion engine that resolves ${VAR}, $VAR, and default fallback syntax (${VAR:-default}, ${VAR-default}). Supports nested fallbacks, escaping with backslashes, and circular reference detection. The expander first checks a provided context dictionary, then falls back to system environment variables. It is fully self-contained (no internal project dependencies) and could be extracted as a standalone utility for any .NET project needing shell-like variable substitution.
Parses raw lines from .env files into key-value pairs. Handles single and double quoted values with proper escape sequence unescaping, multi-line values spanning multiple rows, inline comment stripping (when enabled), export syntax, and optional variable expansion integration. The parser uses a stateful approach to track open quotes across lines and correctly handles backslash-escaped quotes. While it references internal types (VariableExpander, DotEnvOptions), the core parsing logic is isolated and demonstrates careful handling of edge cases common to .env file formats.