.NET Core 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();
}
 
 
 

public Startup()
{
var buiider = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("AppSettings.json");
Configuration = buiider.Build();
}

posted @ 2018-10-30 13:43  六个字的名字  阅读(2259)  评论(0编辑  收藏  举报