我正在尝试将appsettings转换添加到。net core 2控制台应用程序,例如。
-
应用程序设置。json
-
应用程序设置。测验json
-
我发现以下代码适用于asp。净核心:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange:
true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional:
true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
然而,我不知道如何获得
env.EnvironmentName
因为没有
IHostingEnvironment