标签:href style code icc builder 控制台 com ocs setting
https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration/?tabs=basicconfiguration
Nuget 添加
Microsoft.Extensions.Configuration.Json
Microsoft.Extensions.Options.ConfigurationExtensions
using Microsoft.Extensions.Configuration; using System; using System.IO; namespace RConsoleCore { class Program { public static IConfiguration Configuration { get; set; } static void Main(string[] args) { // 读取配置文件 var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); Configuration = builder.Build(); // 方式1 直接读取节点 Console.WriteLine($"{Configuration.GetSection("Version").Value}"); // 方式2 绑定对象 MySettings app = new MySettings(); Configuration.GetSection("appsetting").Bind(app); // 方式3 绑定对象(推荐方式) MySettings app2 = Configuration.GetSection("appsetting").Get<MySettings>(); Console.ReadKey(); } } }
标签:href style code icc builder 控制台 com ocs setting
原文地址:https://www.cnblogs.com/james641/p/8760582.html