In a .NET 6 / 7 web project, the default builder is used on the very first line
var builder = WebApplicationBuilder.CreateBuilder();
And this builder then has configs such as "appsettings.json" and "appsettings.Development.json" included in it.
The documentation says:
... initializes a new instance of the WebApplication class with preconfigured defaults
But I don't want those defaults. I'd like to get rid of appsettings and appsettings.development.
I used to be able to do this in lower versions of .NET using the builder.Host with Clear or something but now it seems I can only add to those default configs? Or do I have to use the older class libraries to get full control of the configs etc.?
You can clear them out:
var builder = WebApplication.CreateBuilder(args);
builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
{
config.Sources.Clear();
});
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