I am trying to add appsettings transformation to a .net core 2 console application e.g.
- appSettings.json
- appSettings.Test.json
- appSettings.Prod.json
I have found the following code works for asp.net core:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange:
true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional:
true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
However, I don't know how to get env.EnvironmentName because there is no IHostingEnvironment in a console app.
Any help will be appreciated
Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Applicationdoesn't contain any environment information - Aman B