This is how I set EnvironmentName
variable when publishing my application:
dotnet publish -c Release -r win-x64 /p:EnvironmentName=MyCustomValue
I got that from this link:
How to set ASPNETCORE_ENVIRONMENT to be considered for publishing an ASP.NET Core application
As a result my application will try to find settings values from:
appsettings.MyCustomValue.json
file and if that file does not exist it will attempt to get it from appsettings.json
.
Anyways I will like to change the value of EnvironmentName
variable at runtime. The reason is because I only want to publish my application once and distribute it to multiple servers. It makes no sense to have to publish the same application multiple time each with a different EnvironmentName
variable.
This is what I have tried doing
WebApplicationBuilder builder = WebApplication.CreateBuilder();
builder.WebHost.UseEnvironment(System.IO.File.ReadAllText(/path/to/some/file...));
But that does not work.