© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
14 replies
hawk4031

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
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
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

EF Core
C#CC# / help
2y ago
Ef core help
C#CC# / help
10mo ago
✅ EF Core Relationship
C#CC# / help
2y ago
EF Core HasPrecision()
C#CC# / help
2y ago