hawk4031
hawk4031
CC#
Created by hawk4031 on 3/30/2024 in #help
EF Core and environment variables
Hello! I have a project that is running with .NET 8.0 (but originally generated from 3.1, so not using the new Startup file type). It's a WebApi project with EF Core. I am trying to generate a DbContext script using dotnet ef dbcontext script but receiving an error. The error has to do with an environment variable reference in the Startup class that is coming back as null. My environment variables are stored in a file called .env. When I run the project through VS Code, the launch.json has a reference to the .env file and all is well. But when I run the EF Core CLI, the environment variables aren't getting picked up, even when I source the environment variable file in the terminal with source .env (this is on macOS). My question is: how can I get the EF Core CLI to play nice with the environment variables that are stored in the file so I don't get errors?
15 replies