SyntaxCircus.DotEnv 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package SyntaxCircus.DotEnv --version 0.1.1
                    
NuGet\Install-Package SyntaxCircus.DotEnv -Version 0.1.1
                    
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="SyntaxCircus.DotEnv" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyntaxCircus.DotEnv" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="SyntaxCircus.DotEnv" />
                    
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 SyntaxCircus.DotEnv --version 0.1.1
                    
#r "nuget: SyntaxCircus.DotEnv, 0.1.1"
                    
#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 SyntaxCircus.DotEnv@0.1.1
                    
#: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=SyntaxCircus.DotEnv&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=SyntaxCircus.DotEnv&version=0.1.1
                    
Install as a Cake Tool

SyntaxCircus.DotEnv

Build NuGet License: MIT

Reusable local dotenv configuration for ASP.NET Core hosts — and a second entry point for hosts that don't build an IConfigurationBuilder at all.

No support guaranteed. Published as-is and maintained on a best-effort basis. Issues and PRs are welcome, but there's no SLA — fork it or vendor what you need if that's not enough.

ASP.NET Core hosts

var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddUserSecrets<Program>(optional: true);

if (builder.Configuration.ShouldLoadDotEnv(builder.Environment))
{
    builder.Configuration.AddSyntaxCircusDotEnvFiles(builder.Environment.ContentRootPath);
    builder.Configuration.AddEnvironmentVariables();
}

builder.Configuration.AddUserSecrets<Program>(optional: true);

The default is enabled in Development and disabled elsewhere. Set DotEnv:Enabled to true or false in normal host configuration to override that default.

When enabled, .env is loaded before .env.local; .env.local overrides it. Both are below process/container environment variables and user secrets. Keys using __ map to the normal : configuration path separator.

Monorepo hosts sharing one .env file

If several hosts in the same repo (an API, a Web app, a Worker, ...) share one .env file, pass a hostPrefix so each host only picks up its own overrides plus whatever isn't prefixed at all:

builder.Configuration.AddSyntaxCircusDotEnvFiles(
    builder.Environment.ContentRootPath,
    hostPrefix: "MyAppApi__",
    knownHostPrefixes: ["MyAppApi__", "MyAppWeb__", "MyAppWorker__"]);

A key like MyAppApi__ConnectionStrings__Default=... only applies when hostPrefix is "MyAppApi__" (with the prefix stripped before the __: mapping); a key like Logging__LogLevel__Default=Information with no matching prefix applies everywhere.

Non-ASP.NET-Core hosts (console apps, workers)

For hosts that set up their own environment before anything reads IConfiguration — or that don't use Microsoft.Extensions.Configuration at all — call DotEnvProcessLoader early in Main, before anything reads environment variables:

DotEnvProcessLoader.LoadFromRepositoryRoot(AppContext.BaseDirectory);

This walks up to the nearest .git directory, then sets real process environment variables from .env and .env.local (never overwriting a variable that was already set before either file loaded; .env.local overrides .env).

Contributing

Issues and pull requests are welcome:

  • Keep changes focused, with a clear description of the behavior change.
  • Match the existing code style (see .editorconfig).
  • Call out any breaking changes to the public API in your PR description.

License

MIT — see LICENSE.txt.

Product Compatible and additional computed target framework versions.
.NET 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

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
0.1.3 122 9/4/2026
0.1.2 595 8/17/2026
0.1.1 103 8/16/2026