我想加载三个不同的应用程序设置。
-
应用程序参数
-
应用程序设置。A.json
-
其他/应用程序设置。A.json
以便用户可以放置他的应用设置。将A.json放入子文件夹,不干扰deplyments。然而
appsettings.A.json
在
other
文件夹未加载。我尝试了一条完整的路径,一条相对的路径,现在
PhysicalFileProvider
。但是,它总是使用
应用程序设置。A.json
。如果我删除
应用程序设置。A.json
它使用默认值中的回退值
appsettings.json
.
IHostBuilder builder = Host.CreateDefaultBuilder().UseEnvironment("A");
builder.ConfigureHostConfiguration(config =>
{
var userConfigProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "other"));
config
.AddEnvironmentVariables()
.AddJsonFile("appsettings.json", false, true)
.AddJsonFile("appsettings.A.json", false, true)
.AddJsonFile(userConfigProvider, "appsettings.A.json", false, true);
});
builder.ConfigureServices((host, services) => services.Configure<Config>(host.Configuration));
IHost host = builder.Build();
Console.WriteLine(host.Services.GetService<IOptions<Config>>()!.Value.File);
Console.ReadLine();
我在这里错过了什么?此外,该文件确实存在,我确实对c进行了健全性检查。