我是一位有帮助的助手,以下是您需要翻译的内容:
然而,当我创建一个新的系统变量时,该应用程序无法看到它。
如果我将鼠标悬停在配置上,我会看到JsonConfigurationProvider和EnvironmentVariablesConfigurationProvider,但是我创建的那些不在列表中。
例如,我在我的机器上创建了一个新的系统环境变量,名为Database。我想我可以使用 configuration.GetValue("Database") 调用它。
这是我加载配置的方式。
我正在使用C# .NET Core 2.1控制台应用程序。我可以使用以下方法查看预定义的系统环境变量:
configuration.GetValue<string>("TMP")
然而,当我创建一个新的系统变量时,该应用程序无法看到它。
如果我将鼠标悬停在配置上,我会看到JsonConfigurationProvider和EnvironmentVariablesConfigurationProvider,但是我创建的那些不在列表中。
例如,我在我的机器上创建了一个新的系统环境变量,名为Database。我想我可以使用 configuration.GetValue("Database") 调用它。
这是我加载配置的方式。
configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables().Build();
有任何建议吗?请记住,我使用的是控制台应用程序而不是ASP.NET。