The configuration file 'appsettings.json' was not found and is not optional
Posted on 2017-05-02 17:13 冰碟 阅读(4014) 评论(0) 编辑 收藏 举报问:
.Net Core: Application startup exception: System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional.
答:
问题代码:
public Startup()
{
var builder = new ConfigurationBuilder().AddJsonFile("AppSetting.json");
Configuration = builder.Build();
}
正确代码:
public Startup(IHostingEnvironment environment)
{
var builder = new ConfigurationBuilder().SetBasePath(environment.ContentRootPath).AddJsonFile("AppSetting.json");
Configuration = builder.Build();
}