DotEnv.Core 1.1.2

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

// Install DotEnv.Core as a Cake Tool
#tool nuget:?package=DotEnv.Core&version=1.1.2

dotenv.core

dotenv-logo

dotenv.core dotenv.core dotenv.core Nuget-Badges

dotenv.core is a class library for read and parsing .env files in .NET Core and also provides a mechanism to retrieve the value of an environment variable in a simple and easy way.

Features

  • It has a fluent interface, which makes it simple and easy to use.
  • Support for load multiple .env files.
  • Searches in parent directories when it does not find the .env file in the current directory.
  • You can customize the parser algorithm through inheritance.
  • You can set the base path for a set of .env files.
  • You can change the default .env file name, so it does not necessarily have to be .env.
  • Support for the variables interpolation.

Don't forget to visit the official library website where you can find API documentation, articles and diagrams.

Basic Concepts

What is a .env file?

A .env file or dotenv file is a simple text configuration file for controlling your Applications environment constants.

What do .env files look like?

.env files are line delimitated text files, meaning that each new line represents a single variable. By convention .env variable names are uppercase words separated by underscores. Variable names are followed directly by an = which, in turn is followed directly by the value, for example:

VARIABLE_NAME=value

What is environment variable?

An environment variable is a dynamic variable that can affect the behavior of running processes on a computer. They are part of the environment in which a process runs.

Installation

If you're an hardcore and want to do it manually, you must add the following to the csproj file:

<PackageReference Include="DotEnv.Core" Version="1.1.2" />

If you're want to install the package from Visual Studio, you must open the project/solution in Visual Studio, and open the console using the Tools > NuGet Package Manager > Package Manager Console command and run the install command:

Install-Package DotEnv.Core

If you are making use of the dotnet CLI, then run the following in your terminal:

dotnet add package DotEnv.Core

Usage

You must import the namespace types at the beginning of your class file:

using DotEnv.Core;

Then you can load the .env file with the Load method of the EnvLoader class:

new EnvLoader().Load();

By default, the Load method will look for a file called .env in the current directory and if it does not find it, it will look for it in the parent directories of the current directory.

The current directory is where the executable with its dependencies is located.

Remember that if no encoding is specified to the Load method, the default will be UTF-8.

After you have loaded the .env file with the Load method, you can access the environment variables using the indexer of the EnvReader class:

var reader = new EnvReader();
string key1 = reader["KEY1"];
string key2 = reader["KEY2"];

Or you can also access the environment variables using the static property Instance:

string key1 = EnvReader.Instance["KEY1"];
string key2 = EnvReader.Instance["KEY2"];

For more information, see the articles.

Deployment in Production

In production, you should not add sensitive data (such as passwords) to an .env file, as it would be unencrypted! Instead, you should use a secrets manager such as Azure Key Vault or AWS Secrets Manager.

Contribution

If you want to contribute in this project, simply fork the repository, make changes and then create a pull request.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DotEnv.Core:

Package Downloads
Dotenv.Extensions.Microsoft.DependencyInjection

Adds dotenv.core extensions for Microsoft.Extensions.DependencyInjection

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on DotEnv.Core:

Repository Stars
ose-net/yesql.net
YeSQL.NET is a class library for loading SQL statements from .sql files instead of writing SQL code in your C# source files
Version Downloads Last updated
3.0.0 42,791 5/3/2023
2.3.2 8,646 1/21/2023
2.3.1 1,327 11/24/2022
2.3.0 512 11/17/2022
2.2.1 1,348 7/4/2022
2.2.0 389 6/30/2022
2.1.0 395 5/30/2022
2.1.0-alpha3 132 5/13/2022
2.1.0-alpha2 149 5/10/2022
2.1.0-alpha1 140 5/5/2022
2.0.1 4,834 4/30/2022
2.0.0 412 3/29/2022
1.1.3 263 1/3/2022
1.1.2 227 12/31/2021
1.0.2 237 12/24/2021
1.0.1 258 12/18/2021
1.0.0 286 12/16/2021