.net core 特定于环境的appsettings未加载其数据
当我尝试使用自定义appsettings.{environment}.json文件时,即使ASPNETCORE_环境变量正确设置为“Local”,并且配置源中引用了appsettings.Local.json文件,也不会从中读取任何数据,只会从appsettings.json读取数据.net core 特定于环境的appsettings未加载其数据,.net-core,.net Core,当我尝试使用自定义appsettings.{environment}.json文件时,即使ASPNETCORE_环境变量正确设置为“Local”,并且配置源中引用了appsettings.Local.json文件,也不会从中读取任何数据,只会从appsettings.json读取数据 public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(ar
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
// Configure the app here.
var env = context.HostingEnvironment;
//var environmentName =
config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
config.AddEnvironmentVariables();
})
.UseStartup<Startup>();
我要做的第一件事是将其更改为
可选:false
,并确保它正在查找文件。这不要紧,但您添加的源实际上是您显示的列表中的[5]
。是的,就是这样。我的生成未将其生成到/bin文件夹中
------ appsettings.json ----------------------
{
"AllowedHosts": "*",
"AppSettings": {
"MailServer": "mail.somewhare.com",
"SupportContact": "somebody@somewhare.com",
"EmailEnabled": true
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
------ appsettings.Local.json ---------------
{
"ConnectionStrings": {
"Dbconn1": "string 1 here",
"DbConn2": "string 1 here"
},
"AllowedHosts": "*",
"AppSettings": {
"CustomerBoxRoot": "\\\\test1\\d$\\BoxFiles",
"AnotherAppSetting": 20,
"PurgeSwitch": -14
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}