0
votes

I have defined below structure in my project.


    appsettings.json
      appsettings.development.json
      appsettings.prod.json
      appsettings.uat.json

Program.cs

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }
    
        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
                    {
                        var env = hostingContext.HostingEnvironment;
                        config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
                    });
                    webBuilder.UseStartup<Startup>();
                });
    }

I want server to read stage specific appsettings file. But all environments are reading appsettings.json always.

I don't know if case-sensitivity is important - have you tried appsetings.Development.json? Also the production environment is normally 'Production' not 'prod' - unless you are setting it manually somewhere. Also: config cascades, so it will always read appsettings.json, and then override those with subsequent config options.bfren
In yml file, i have defined env mappings ``` AppEnvMap: legacy: dev: Development qa: qa uat: uat prod: prod ```user14463446