I have developed a web API and published it on azurewebsites.net. I have added the following additional appsettings:-
- appsettings.Dev.json
- appsettings.Test.json
- appsettings.Prod.json
To be able to extract values from these appsettings transforms I made the following code changes:
Tried the solution mentioned here: https://stackoverflow.com/a/44953524/10485667
Even tried using only the Development/Debug, Staging and Production/Release instead of Dev, Test, Prod receptively. But no luck. It would only publish the values from the main appsettings.json.
Startup.cs
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
#if DEBUG
.AddJsonFile($"appsettings.Dev.json", optional: true)
#endif
.AddEnvironmentVariables();
Configuration = builder.Build();
appSettings = Configuration.Get<AppSettingsModel>().AppSettings;
}
even tried this code:
AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
Tried changing the Program.cs:
public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddJsonFile($"appsettings.Development.json", optional: true)
.Build();
ILogger logger = null;
var host = CreateWebHostBuilder(args)
.UseConfiguration(config)
.Build();
logger = host.Services.GetService<ILogger>();
host.Run();
}
}
Tried every possible solution provided on internet but no luck. After publishing to azure, it takes the values only from appsettings.json
I think I might be making some conceptual mistake while attempting these solutions. Any kind of help is appreciated.
Thanks in advance