When I change my ASPNETCORE_ENVIRONMENT to "staging" or anything else on my local machine the application is seeing the environment name as "Development".
My Environment variable is currently set up like this:
And my Startup class constructor is:
public Startup(IWebHostEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
Env = env;
}
But When I run the application and hover over env.EnvironmentName I see "Development". When I run this on the staging server which also has its ASPNETCORE_ENVIRONMENT set to "Staging" it's transformed to "Production".
It's as if the application isn't looking for the variable at all.
I've been staring at this for a while and using my favorite search engine to find an answer but I'm a little stumped. I know I have done this before without issue.
Advice would be much appreciated.
This is how I "fixed" it.
I was personally unaware that when adding an environment variable the machine on which it's being added must be restarted. After restarting the staging server, the environment is being correctly picked up.
Hopefully someone arriving via Google search might find this useful one day.