I want to put my appsettings.json file outside of the web folder so that I can avoid storing it in source control. How can I do this?
It doesn't like relative paths, it seems. But, this works...
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
if (!hostingContext.HostingEnvironment.IsDevelopment())
{
var parentDir = Directory.GetParent(hostingContext.HostingEnvironment.ContentRootPath);
var path = string.Concat(parentDir.FullName, "\\config\\appsettings.json");
config.AddJsonFile(path, optional: false, reloadOnChange: true);
}
})
.UseStartup<Startup>()
.Build();
So, it's another settings file on top of the sources added by default.