Yes, it's very easy. Currently, you are most likely using the Debug
solution configuration for local development. Let's assume you also have Release
as solution configuration and want to change certain settings upon publishing to Azure / with your publish profile.
Assuming you are using .NET Core 3.1 (also works with 2.x but the syntax is different), you can this code:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseEnvironment(Environment);
});
public static string Environment
{
get
{
string environmentName;
#if DEBUG
environmentName = "development";
#elif RELEASE
environmentName = "production";
#endif
return environmentName;
}
}
Also create a appsettings.product.json
where you override specific values.
When you use your publish profile, simply select Release
as solution configuration in the publish dialog. That way, you application will load appsettings.json
for default values which will be overwritten by values in appsettings.production.json
.
You can read more details in the docs.