【发布时间】:2018-09-15 00:50:14
【问题描述】:
我正在将 apt.net core 2.0 web api 部署为 Windows 服务。我的每个环境都有一个 appsettings 文件(例如:appsettings.Development.json)。
但是,我的环境特定 appsetting 文件未加载到我的配置中。这是代码:
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
return WebHost.CreateDefaultBuilder(args)
.UseContentRoot(pathToContentRoot)
.ConfigureAppConfiguration((builderContext, config) =>
{
IHostingEnvironment env = builderContext.HostingEnvironment;
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile("appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
//.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
})
.UseStartup<Startup>()
.UseUrls(myUrl)
.Build();
我尝试通过硬编码(注释中的代码)值来加载特定于环境的配置文件,该值有效。我还可以保证我的环境名和文件名之间没有错字。
我的环境名称是通过部署机器上的环境变量设置的。
【问题讨论】:
标签: asp.net-core-2.0