gpt4 book ai didi

c# - 为 ASP.NET Core 配置引用 appsettings.json 中的另一个 json 文件

转载 作者:太空狗 更新时间:2023-10-29 18:21:32 26 4
gpt4 key购买 nike

在“过去”使用 XML 配置时,可以包含来自另一个文件的部分配置,例如 this :

<appSettings file="relative file name">
<!-- Remaining configuration settings -->
</appSettings>

现在在 ASP.NET Core 中,我想在 appsettings.Development.json 中分享一些配置以及例如 appsettings.Staging.json .类似于 <appSettings file="">也可以使用 json 配置吗?

最佳答案

可以在Startup类中添加多个配置文件:

public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile("appsettings-Development.json", optional: false)
.AddJsonFile("appsettings-Staging.json", optional: false)
.AddEnvironmentVariables();
Configuration = builder.Build();
}

查看此处了解更多详情:https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration ...

关于c# - 为 ASP.NET Core 配置引用 appsettings.json 中的另一个 json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46058664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com