How can I add a custom JSON file into IConfiguration?

For .Net Core 2.2, you need to modify Program.cs:

Before

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
           .UseStartup<Startup>();

After

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)

            //This is how you attach additional JSON files
            .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.AddJsonFile("customSettings.json", optional: false, reloadOnChange: false);
            })
            //End of update
            .UseStartup<Startup>();

For the latest amendments and to add other kinds of custom settings, please refer to Microsoft documentation at the following article.

Leave a Comment