本文主要是介绍.NET Core项目读取配置文件使用Microsoft.Extensions.Configuration,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
配置文件config.xml:
<?xml version="1.0" encoding="utf-8" ?>
<!--配置文件不允许有&符号-->
<appSettings> <token>token=SADFASDF;oudes=430815;kdm=56756756;padf=56565</token><cookie>NAME=HANSDU;AUG=345354;PASS=3434</cookie>
</appSettings>
//Nuget中添加引用Microsoft.Extensions.Configuration
//Nuget中添加引用Microsoft.Extensions.Configuration.Xml
static void Main(string[] args)
{ var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddXmlFile("config.xml");IConfiguration _configuration = builder.Build();string token = _configuration["token"];token = token.Replace(";","&");string cookie = _configuration["cookie"];Console.ReadKey();
}
微软官方参考
https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.1&tabs=basicconfiguration
这篇关于.NET Core项目读取配置文件使用Microsoft.Extensions.Configuration的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!