【发布时间】:2016-09-12 02:30:10
【问题描述】:
我正在尝试在我的应用程序中使用环境变量,因此我不必费心维护跨不同系统的配置文件。也许我只是对这些变量的来源有一个误解。
首先,我在本地 System -> Advanced 属性上创建了一个名为 MediatrExampleDbConnection 的 Windows 系统变量
然后,我的 Startup.cs 中有这段代码:
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
当我稍后尝试访问它时,它又回来了 null :
var MediatrConnectionString = Configuration["MediatrExampleDbConnection"];
这不是应该从我的本地系统变量中提取的吗,因为我在那里有.AddEnvironmentVariables();?
【问题讨论】:
标签: c# asp.net asp.net-core