DotNetEnv 1.2.0
See the version list below for details.
dotnet add package DotNetEnv --version 1.2.0
NuGet\Install-Package DotNetEnv -Version 1.2.0
paket add DotNetEnv --version 1.2.0
#r "nuget: DotNetEnv, 1.2.0"
#:package DotNetEnv@1.2.0
#addin nuget:?package=DotNetEnv&version=1.2.0
#tool nuget:?package=DotNetEnv&version=1.2.0
dotnet-env
A .NET library to load environment variables from .env files. Supports .NET Core and .NET Framework
Installation
Available on NuGet
Visual Studio:
PM> Install-Package DotNetEnv
.NET Core CLI:
dotnet add package DotNetEnv
Usage
Load env file
Load() will automatically look for a .env file in the current directory
DotNetEnv.Env.Load();
Or you can specify the path to the .env file
DotNetEnv.Env.Load("./path/to/.env");
It's also possible to load the (text) file as a Stream
using (var stream = File.OpenRead("./path/to/.env"))
{
DotNetEnv.Env.Load(stream);
}
Accessing environment variables
The variables in the .env can then be accessed through the System.Environment class
System.Environment.GetEnvironmentVariable("IP");
Or through on of the helper methods:
DotNetEnv.Env.GetString("A_STRING");
DotNetEnv.Env.GetBool("A_BOOL");
DotNetEnv.Env.GetInt("AN_INT");
DotNetEnv.Env.GetDouble("A_DOUBLE");
The helper methods also has a optional second argument which specifies what value to return if the variable is not found:
DotNetEnv.Env.GetString("THIS_DOES_NOT_EXIST", "Variable not found");
Additional arguments
You can also control whitespace trimming and allowing hashes in values
DotNetEnv.Env.Load(false, false);
Both parameters default to true, which means:
trimWhitespace, first arg: true in order to trim leading and trailing whitespace from keys and values such that
KEY = value
Would then be available as
"value" == System.Environment.GetEnvironmentVariable("KEY")
null == System.Environment.GetEnvironmentVariable(" KEY ")
False would mean:
" value" == System.Environment.GetEnvironmentVariable(" KEY ")
null == System.Environment.GetEnvironmentVariable("KEY")
isEmbeddedHashComment, second arg: true in order to allow inline comments
KEY=value # comment
Would then be available as
"value" == System.Environment.GetEnvironmentVariable("KEY")
False would mean:
"value # comment" == System.Environment.GetEnvironmentVariable("KEY")
Which is most useful when you want to do something like:
KEY=value#moreValue#otherValue#etc
unescapeQuotedValues, third arg: true in order to unescape/parse quoted (single or double) values as being strings with escaped chars such as newline ("\n"), but also handles unicode chars (e.g. "\u00ae" and "\U0001F680") -- note that you can always include unescaped unicode chars anyway (e.g. "日本") if your .env is in UTF-8. Also note that there is no need to escape quotes inside.
KEY="quoted\n\tvalue"
Would then be available as
"quoted
value" == System.Environment.GetEnvironmentVariable("KEY")
False would mean:
"\"quoted\\n\\tvalue\"" == System.Environment.GetEnvironmentVariable("KEY")
clobberExistingVars, fourth arg: false to avoid overwriting existing environment variables
KEY=value
System.Environment.SetEnvironmentVariable("KEY", "really important value, don't overwrite");
DotNetEnv.Env.Load(false, false, false, false); // fourth arg false, don't overwrite existing variables
System.Environment.GetEnvironmentVariable("KEY"); // == "really important value, don't overwrite"
Issue Reporting
If you have found a bug or if you have a feature request, please report them at this repository issues section.
License
This project is licensed under the MIT license. See the LICENSE file for more info.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
| .NET Framework | net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
| Universal Windows Platform | uap was computed. uap10.0 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
NuGet packages (82)
Showing the top 5 NuGet packages that depend on DotNetEnv:
| Package | Downloads |
|---|---|
|
hexasync.infrastructure.dotnetenv
Package Description |
|
|
CLUtilitarios
access to redis for obtain user data |
|
|
getstream-net
Official .NET SDK for GetStream Feed API |
|
|
SeliseBlocks.Genesis
Blocks Genesis |
|
|
pagglo_sdk
Package Description |
GitHub repositories (20)
Showing the top 20 popular GitHub repositories that depend on DotNetEnv:
| Repository | Stars |
|---|---|
|
danielgerlag/workflow-core
Lightweight workflow engine for .NET Standard
|
|
|
Azure/data-api-builder
Data API builder provides modern REST, GraphQL endpoints and MCP tools to your Azure Databases and on-prem stores.
|
|
|
mehdihadeli/food-delivery-microservices
🍔 A practical and cloud-native food delivery microservices, built with .Net Aspire, .Net 10, Wolverine, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
|
|
|
TheAxelander/OpenBudgeteer
OpenBudgeteer is a budgeting app based on the Bucket Budgeting Principle
|
|
|
streetwriters/notesnook-sync-server
Sync server for Notesnook (self-hosting in alpha)
|
|
|
spark-dotnet/framework
Build production ready, full-stack web applications fast without sweating the small stuff.
|
|
|
cxfksword/jellyfin-plugin-danmu
jellyfin弹幕自动下载插件
|
|
|
anobaka/Bakabase
A local media manager for all types of files. 二次元老司机专用的本地媒体文件管理器,支持管理和处理音视频、本子、图集、小说、哔哩哔哩视频、游戏甚至mod等各类资源,集成steam、DLsite、exhentai等平台。
|
|
|
mehdihadeli/food-delivery-modular-monolith
🌭 A practical and imaginary food and grocery delivery modular monolith, built with .Net 8, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
|
|
|
mehdihadeli/vertical-slice-api-template
🍰 An asp.net core template based on .Net 9, Vertical Slice Architecture, CQRS, Minimal APIs, OpenTelemetry, API Versioning and OpenAPI.
|
|
|
lminlone/repliqate
A modular Docker container/volume backup solution
|
|
|
sayedihashimi/template-sample
|
|
|
Altinn/altinn-studio
Next generation open source Altinn platform and applications.
|
|
|
Brick-Abode/pldotnet
Build PostgreSQL functions, procedures, and triggers in C# and F#
|
|
|
Tbeninnovation/Baiss
|
|
|
nightscout/nocturne
A next-generation platform for diabetes management
|
|
|
madeyoga/AuthEndpoints
A composable authentication endpoints library for aspnetcore.
|
|
|
jongio/memealyzer
Memealyzer is an app built to demonstrate some the latest and greatest Azure tech to dev, debug, and deploy microservice applications.
|
|
|
MerrionComputing/EventsSourcing-on-Azure-Functions
A library to demonstrate doing Event Sourcing as a data persistence mechanism for Azure Functions
|
|
|
Waifu-im/waifu-api
An easy to use API that allows you to get waifu pictures from an archive of over 4000 images and multiple tags!
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.2.0 | 2,370,043 | 4/26/2026 |
| 3.1.1 | 15,189,347 | 8/20/2024 |
| 3.1.0 | 423,698 | 7/30/2024 |
| 3.0.0 | 3,386,202 | 1/6/2024 |
| 2.5.0 | 3,163,879 | 2/3/2023 |
| 2.3.0 | 2,397,223 | 1/15/2022 |
| 2.2.0 | 527,180 | 9/18/2021 |
| 2.1.1 | 802,866 | 3/2/2021 |
| 2.1.0 | 12,638 | 2/22/2021 |
| 2.0.0 | 164,717 | 12/16/2020 |
| 1.4.0 | 1,080,763 | 12/9/2019 |
| 1.3.1 | 2,835 | 12/5/2019 |
| 1.2.0 | 536,854 | 4/5/2018 |
| 1.1.0 | 14,210 | 11/2/2017 |
| 1.0.1 | 6,365 | 6/18/2017 |
| 1.0.0 | 27,237 | 7/7/2016 |