Loading Environment Variables From .env File - gecko-8/devwiki GitHub Wiki
Note: Uses this package - DotNetEnv
- Add the DotNetEnv package from Nuget.
- Open your Program.cs file.
- Add a ConfigureAppConfiguration call to your WebHost.CreateDefaultBuilder(args) call in CreateWebHostBuilder.
Note: The file path should be relative to the location of your Program.cs file.ConfigureAppConfiguration((hostingContext, config) => { DotNetEnv.Env.Load("../../.env"); }).
Note: It's important to do it this way say that Code-First Migrations work.