var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json"); var configuration = builder.Build();
string baseUrl = configuration.GetSection("baseUrl").Value;
appsettings.json
{ "baseUrl": "http://duyaonet.com" }
.net core 出错 appsettings.json' was not found and is not optional. 找不到文件
解决办法
appsettings.json的属性 复制到输出目录: 始终复制