我的 appsettings 文件确实有效,我看到它们是根据我使用的启动配置文件使用的,但是我的本地主机配置文件不起作用,因为它似乎不存在于我使用的实际框架中。无论如何要添加一个自定义的,例如“本地主机”?
编辑:
谢谢!
最佳答案
在您的 Program.cs 中,添加对 config.AddJsonFile()
的调用:
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile("appsettings.Localhost.json", optional: true);
})
.UseStartup<Startup>();
关于visual-studio-2017 - 在 ASP.NET Core 中使用自定义环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54443927/