问题
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?
回答1:
If you want to use an appsettings.xml
instead you can refer to my blog article here.
Quote from the article:
To use XML files, you need to add this NuGet package: Microsoft.Extensions.Configuration.Xml. I added the 1.0.0 to my project.json and added a appsettings.xml file.
<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)
来源:https://stackoverflow.com/questions/40036819/how-to-pull-configuration-settings-from-xml-file-in-startup-cs