我正在尝试为不同的环境添加 appsettings json 文件。如何在 .NET8 的 Program .cs 中获取如下所示的环境名称:
var options = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
#if DEBUG
.AddJsonFile("local.settings.json")
#else
.AddJsonFile("appsettings(pass the env name).json")
#endif
.Build();
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.Build();
host.Run();
这里有几个帖子,但这些帖子都不被 .NET8 识别,大多数都是针对 .NET6 的
构建();
var host = new HostBuilder() .ConfigureFunctionsWorkerDefaults() .ConfigureServices(services => { services.AddApplicationInsightsTelemetryWorkerService(); services.ConfigureFunctionsApplicationInsights(); }) .Build();主机.运行(); 主机.Run();