原文:
.NET Core中使用读取配置文件
引入Nuget的两个类库
Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.Json
使用
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json"); var configurationRoot = builder.Build(); var motherNameSection = configurationRoot.GetSection("mother").GetSection("name");