【发布时间】:2019-03-12 20:24:31
【问题描述】:
我们有 .NET Core 2.2 Web API 项目,我们使用以下代码根据 DEBUG 或 RELEASE 构建标志加载适当的 appsettings.json 文件。
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseConfiguration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
#if DEBUG
.AddJsonFile("appsettings.Development.json")
#endif
#if RELEASE
.AddJsonFile("appsettings.Production.json")
#endif
.AddJsonFile("appsettings.json")
.Build()
)
.UseStartup<Startup>()
.Build();
我们创建了一个外部项目,它在 Topshelf Windows 服务项目中调用相同的方法。
奇怪的是appsettings.Production.json文件总是被加载,不管我们是在调试还是发布项目。
【问题讨论】:
-
appsettings.json有什么价值?生产还是开发?
标签: c# asp.net-core .net-core appsettings