.NET Core The configuration file 'appsettings.json' was not found and is not optional

Posted 六个字的名字

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.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();
}





以上是关于.NET Core The configuration file 'appsettings.json' was not found and is not optional的主要内容,如果未能解决你的问题,请参考以下文章

asp.net core发布到iis后出现An error occurred while starting the application

Asp.Net Core 发布异常 502.5 [The Application process failed to Start]

Visual Studio 2019 编译.Net Core Console项目出现MSB4018 The "CreateAppHost" task failed unexpec(

.NET Core The configuration file 'appsettings.json' was not found and is not optional

[转].Net Core Web应用发布至IIS后报“An error occurred while starting the application”错误

.net core Docker Compose启动问题: Debugging Error, The program to be debug con not be found in the conta