I am trying to add appsettings transformation to a .net core 2 console application e.g.
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
Couldn't find anything else so using preprocessor directives for now
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if
public Startup()
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange:
true)
#if RELEASE
.AddJsonFile($"appsettings.Release.json", optional:
true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With