dotenv.net
1.0.2
See the version list below for details.
dotnet add package dotenv.net --version 1.0.2
NuGet\Install-Package dotenv.net -Version 1.0.2
<PackageReference Include="dotenv.net" Version="1.0.2" />
paket add dotenv.net --version 1.0.2
#r "nuget: dotenv.net, 1.0.2"
// Install dotenv.net as a Cake Addin #addin nuget:?package=dotenv.net&version=1.0.2 // Install dotenv.net as a Cake Tool #tool nuget:?package=dotenv.net&version=1.0.2
dotenv.net
dotenv.net is a zero-dependency module that loads environment variables from a .env file into Environment
.
Contributors
Big ups to those who have contributed to this library. 👏
@bolorundurowb @joliveros @vizeke @merqlove
Usage
Conventional
First install the library as a dependency in your application from nuget
Install-Package dotenv.net
or
dotnet add package dotenv.net
or for paket
paket add dotenv.net
Create a file with no filename and an extension of .env
.
A sample .env
file would look like this:
DB_HOST=localhost
DB_USER=root
DB_PASS=s1mpl3
in the Startup.cs
file or as early as possible in your code add the following:
using DotEnv;
...
DotEnv.Config();
the values saved in your .env
file would be avaibale in your application and can be accessed via
Environment.GetEnvironmentVariable("DB_HOST"); // would output 'localhost'
With ASP.NET Core or any other DI system that uses IServiceCollection
In the Startup.cs
file
public void ConfigureServices(IServiceCollection services)
{
...
// configure dotenv
services.AddEnv(builder => {
builder
.AddEnvFile("/custom/path/to/your/env/vars")
.AddThrowOnError(false)
.AddEncoding(Encoding.ASCII);
});
}
With this, your application would have the env file variables imported.
Options
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.Default
You may specify the encoding of your file containing environment variables using this option.
DotEnv.Config(true, ".env", Encoding.Unicode);
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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.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 | 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 2.0
- Microsoft.Extensions.DependencyInjection (>= 2.0.0)
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 | 16,116 | 9/21/2024 |
3.2.0 | 147,276 | 6/22/2024 |
3.1.3 | 503,441 | 11/5/2023 |
3.1.2 | 1,789,792 | 11/25/2022 |
3.1.1 | 736,967 | 10/11/2021 |
3.1.0 | 108,384 | 7/11/2021 |
3.0.0 | 304,210 | 3/19/2021 |
2.1.3 | 209,467 | 1/18/2021 |
2.1.1 | 180,010 | 5/26/2020 |
2.1.0 | 123,163 | 4/1/2020 |
2.0.1 | 1,854 | 3/27/2020 |
2.0.0 | 1,123 | 3/25/2020 |
1.0.6 | 401,667 | 6/29/2019 |
1.0.5 | 1,278 | 6/27/2019 |
1.0.4 | 118,319 | 10/21/2018 |
1.0.3 | 24,238 | 2/17/2018 |
1.0.2 | 1,518 | 1/15/2018 |
1.0.1 | 1,604 | 12/31/2017 |
1.0.0 | 8,205 | 11/22/2017 |
Make use of a singleton instead of a static class and allow for "=" sign in the value side of an env variable