public class ConfigurationHelper { private static IConfigurationRoot ConfigurationRoot { get { //读取环境变量 string env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var build = new ConfigurationBuilder(); build.SetBasePath(Directory.GetCurrentDirectory()); //根据环境变量加载json配置 build.AddJsonFile($"appsettings.{env}.json", false, false); var configuration = build.Build(); return configuration; } } public static string GetValue(string key) { return ConfigurationRoot.GetSection(key).Value; } }