代码

Github: https://github.com/chengxulvtu/Cxlt.Extensions.Configuration

Nuget搜索 Cxlt.Extensions.Configuration.Yaml

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace Demo.Web.Entry
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((ctx, configBuilder) =>
                {
                    // 加载yaml配置文件
                    configBuilder
                        .AddYamlFile("appsettings.yaml")
                        .AddYamlFile($"appsettings.{ctx.HostingEnvironment.EnvironmentName}.yaml");
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                 	//.. 省略
                });
        }
    }
}

最后修改于 2022-01-03 21:56:42
上一篇