Currently, we use the BUILD CONFIGURATION from the Configuration Manager to drive web.config and app.config configuration-transformation in our builds.
We are in the midst of upgrading to .NET Core & a lot of examples show the use of Environment Variables to drive configuration-transformation in appsettings.json. But I can't seem to find examples that correctly transform the appsettings.json file using BUILD CONFIGURATION.
Q: Is it even possible to let the BUILD CONFIGURATION transform the appsettings.json file anymore?
Q: If so...how?
I am super not interested in going into 100+ servers & setting an environment variable in IIS.
static IHostBuilder CreateHostBuilder(string[] args)
{
var builder = new HostBuilder()
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment; //<-- I dont want to do this
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
})
.UseServiceProviderFactory<ServiceRegistry>(new LamarServiceProviderFactory())
.ConfigureServices((hostContext, services) =>
{
var connectionString = hostContext.Configuration.GetConnectionString(JsonSettings.ConnectionStrings.WorkflowComponentDb);
services.AddLamar(new ContainerRegistry());
services.AddDbContext<IntegrationDbContext>((provider, options) => { options.UseSqlServer(connectionString); });
services.AddOptions();
})
.UseConsoleLifetime();
return builder;
}

