How to load a separate Application Settings file dynamically and merge with current settings?

后端 未结 2 1793
悲哀的现实
悲哀的现实 2020-12-03 01:50

There are questions pertaining to reading settings from a separate config file and others similar to it, but my question is specific to application property settings (i.e. <

2条回答
  •  有刺的猬
    2020-12-03 02:25

    The solution suggested by Pat:

    // Get the whole XML inside the settings node
    var settings = import.XPathSelectElements("//" + appSettingsXmlName);
    

    returns null. I changed it to

    var settings = import.Element("configuration").Element("userSettings").Element(appSettingsXmlName);
    
    config.GetSectionGroup("userSettings")
          .Sections[appSettingsXmlName]
          .SectionInformation
          .SetRawXml(settings.ToString());
    

    And it works perfectly.

提交回复
热议问题