dotenv.net 2.1.1

A library to read variables from a .env file and populate the environment variables.

Install-Package dotenv.net -Version 2.1.1
dotnet add package dotenv.net --version 2.1.1
<PackageReference Include="dotenv.net" Version="2.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add dotenv.net --version 2.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

dotenv.net

CircleCI License: MIT Coverage Status

project icon

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. :clap:

@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

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.

dotenv.net

CircleCI License: MIT Coverage Status

project icon

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. :clap:

@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

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.

Release Notes

- Split the dotenv package into component libs

NuGet packages (6)

Showing the top 5 NuGet packages that depend on dotenv.net:

Package Downloads
Injector
Injects values into config files directly or via environment variables. Can inject app settings, connection strings, or WCF client endpoints.
OneBlink.SDK
.Net version of the OneBlink SDK
CasAuth
The Comprehensive Authentication Solution (or CasAuth) was developed to provide an opinionated way to handle user and service authentication for APIs.
dotenv.net.DependencyInjection.Microsoft
Adds DI support for values read from the environment for Microsoft Service Collection
NetBricks
Commonly used tooling for dotnetcore, including configuration management, logging, etc.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.1.1 4,160 5/26/2020
2.1.0 12,569 4/1/2020
2.0.1 415 3/27/2020
2.0.0 137 3/25/2020
1.0.6 140,740 6/29/2019
1.0.5 282 6/27/2019
1.0.4 70,546 10/21/2018
1.0.3 20,028 2/17/2018
1.0.2 523 1/15/2018
1.0.1 526 12/31/2017
1.0.0 1,733 11/22/2017