如何在.NET8中获取程序cs文件中的环境名称

问题描述 投票:0回答:1

我正在尝试为不同的环境添加 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 的

c# configuration environment .net-8.0
1个回答
0
投票

构建();

var host = new HostBuilder() .ConfigureFunctionsWorkerDefaults() .ConfigureServices(services => { services.AddApplicationInsightsTelemetryWorkerService(); services.ConfigureFunctionsApplicationInsights(); }) .Build();主机.运行(); 主机.Run();

© www.soinside.com 2019 - 2024. All rights reserved.