dotenv.net
2.1.3
See the version list below for details.
dotnet add package dotenv.net --version 2.1.3
NuGet\Install-Package dotenv.net -Version 2.1.3
<PackageReference Include="dotenv.net" Version="2.1.3" />
paket add dotenv.net --version 2.1.3
#r "nuget: dotenv.net, 2.1.3"
// Install dotenv.net as a Cake Addin #addin nuget:?package=dotenv.net&version=2.1.3 // Install dotenv.net as a Cake Tool #tool nuget:?package=dotenv.net&version=2.1.3
dotenv.net
dotenv.net is a group of projects that aim to make the process of reading .env
files as simple and pain-free as possible in the dotnet ecosystem. It contains a core library that holds the env reading functionality and two libraries that add dependency injection (DI) support for two popular DI systems. If you have ideas or issues, feel free to create an issue.
Contributors
Big ups to those who have contributed to these libraries. 👏
@bolorundurowb @joliveros @vizeke @merqlove @tracker1 @NaturalWill @texyh
How to use this documentation
Documentation specific to each project can be found in the README files for the specific projects while common features would be documented
Options
AutoConfig
You can specify if you want the library to search for .env files up the directory chain
DotEnv.AutoConfig(); //silent if no .env file found up the chain
ThrowError
Default: true
You can specify if you want the library to error out if any issue arises or fail silently.
DotEnv.Config(false); //fails silently
Path
Default: .env
You can specify a custom path if your file containing environment variables is named or located differently.
DotEnv.Config(true, "/custom/path/to/your/env/vars");
Encoding
Default: Encoding.UTF8
You may specify the encoding of your file containing environment variables using this option.
DotEnv.Config(true, ".env", Encoding.Unicode);
Trim Values
Default: true
You may specify whether or not you want the values retrieved to be trimmed i.e have all leading and trailing whitepaces removed.
DotEnv.Config(true, ".env", Encoding.Unicode, false);
Support For IEnvReader
With v1.0.6
and above an interface IEnvReader
has been introduced that specifies methods that help with reading typed values from the environment easily. The library has a default implementation EnvReader
.
Using EnvReader
using dotenv.net.Utilities;
...
var envReader = new EnvReader();
var value = envReader.GetValue("KEY");
IEnvReader Methods
string GetStringValue(string key)
Default: null
Retrieve a value from the current environment by the given key and throws an exception if not found.
int GetIntValue(string key)
Default: 0
Retrieve a value from the current environment by the given key and throws an exception if not found.
double GetDoubleValue(string key)
Default: 0.0
Retrieve a value from the current environment by the given key and throws an exception if not found.
decimal GetDecimalValue(string key)
Default: 0.0m
Retrieve a value from the current environment by the given key and throws an exception if not found.
bool GetBooleanValue(string key)
Default: false
Retrieve a value from the current environment by the given key and throws an exception if not found.
bool TryGetStringValue(string key, out string value)
Default: null
A safer method to use when retrieving values from the environment as it returns a boolean value stating whether it successfully retrieved the value required.
bool TryGetIntValue(string key, out int value)
Default: 0
A safer method to use when retrieving values from the environment as it returns a boolean value stating whether it successfully retrieved the value required.
bool TryGetDoubleValue(string key, out double value)
Default: 0.0
A safer method to use when retrieving values from the environment as it returns a boolean value stating whether it successfully retrieved the value required.
bool TryGetDecimalValue(string key, out decimal value)
Default: 0.0m
A safer method to use when retrieving values from the environment as it returns a boolean value stating whether it successfully retrieved the value required.
bool TryGetBooleanValue(string key, out bool value)
Default: false
A safer method to use when retrieving values from the environment as it returns a boolean value stating whether it successfully retrieved the value required.
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. |
.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.6 is compatible. netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | 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. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.6
- System.Memory (>= 4.5.4)
-
.NETStandard 2.0
- System.Memory (>= 4.5.4)
-
.NETStandard 2.1
- System.Memory (>= 4.5.4)
NuGet packages (23)
Showing the top 5 NuGet packages that depend on dotenv.net:
Package | Downloads |
---|---|
NetBricks
Commonly used tooling for dotnetcore, including configuration management, logging, etc. |
|
CodeZero
CodeZero is a set of common implementations to help you implementing Clean Architecture, DDD, CQRS, Specification Patterns and another facilities for new modern web applications is an open-source project written in .NET Core. |
|
MCMS.Base
MCMS Base package |
|
Injector
Injects values into config files directly or via environment variables. Can inject app settings, connection strings, or WCF client endpoints. |
|
CasAuth
The Comprehensive Authentication Solution (or CasAuth) was developed to provide an opinionated way to handle user and service authentication for APIs. |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on dotenv.net:
Repository | Stars |
---|---|
Green-Software-Foundation/carbon-aware-sdk
Carbon-Aware SDK
|
|
redis/NRedisStack
Redis Stack .Net client
|
|
Azure/azure-sdk-tools
Tools repository leveraged by the Azure SDK team.
|
Version | Downloads | Last updated |
---|---|---|
3.2.1 | 62,975 | 9/21/2024 |
3.2.0 | 182,747 | 6/22/2024 |
3.1.3 | 554,231 | 11/5/2023 |
3.1.2 | 1,919,818 | 11/25/2022 |
3.1.1 | 744,362 | 10/11/2021 |
3.1.0 | 110,230 | 7/11/2021 |
3.0.0 | 319,023 | 3/19/2021 |
2.1.3 | 211,382 | 1/18/2021 |
2.1.1 | 181,211 | 5/26/2020 |
2.1.0 | 124,488 | 4/1/2020 |
2.0.1 | 1,883 | 3/27/2020 |
2.0.0 | 1,142 | 3/25/2020 |
1.0.6 | 403,990 | 6/29/2019 |
1.0.5 | 1,284 | 6/27/2019 |
1.0.4 | 118,775 | 10/21/2018 |
1.0.3 | 24,762 | 2/17/2018 |
1.0.2 | 1,526 | 1/15/2018 |
1.0.1 | 1,610 | 12/31/2017 |
1.0.0 | 8,567 | 11/22/2017 |