问题描述
我有一个startup.cs文件,我想从XML文件而不是appsetings.json
文件中提取配置. ASP.NET Core MVC是否可以?
I have a startup.cs file and i want to pull configurations from XML file rather than appsetings.json
file. Is it possible with ASP.NET Core MVC?
推荐答案
如果您想使用appsettings.xml
,则可以参考我的博客文章此处.
If you want to use an appsettings.xml
instead you can refer to my blog article here.
文章引用:
<configuration> <MySettings> <SomeSetting>Test</SomeSetting> <Another>true</Another> </MySettings> </configuration>
<configuration> <MySettings> <SomeSetting>Test</SomeSetting> <Another>true</Another> </MySettings> </configuration>
然后我将其添加为配置的一部分,如下所示:
I then added it as part of configuration like this:
.AddXmlFile("appsettings.xml", optional: true, reloadOnChange: true)
这篇关于如何从Startup.cs中的XML文件中提取配置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!