tonerdo / dotnet-env

A .NET library to load environment variables from .env files
MIT License
427 stars 50 forks source link

Env file not loading #66

Closed Metacinnabar closed 2 years ago

Metacinnabar commented 2 years ago

Description

After running DotNetEnv.Env.Load(); no environment variables are added.

Specifications

I am running EndeavourOS Linux. My code is running on .NET Core 6.

Code

DotNetEnv.Env.Load();
Console.WriteLine("token: " + Environment.GetEnvironmentVariable("TOKEN"));

...with the output of token:

My .env

Located at root/MyProject/.env, where root is where the solution file is located and MyProject is where the project file is located.

TOKEN=token
MrDave1999 commented 2 years ago

You must use the method DotNetEnv.Env.TraversePath().Load();.

rogusdev commented 2 years ago

The real thing that matters is where the binary (exe) is located relative to the .env file. What Dave said is probably going to help though.

Metacinnabar commented 2 years ago

Thank you! This worked perfectly.