简体   繁体   中英

.NET settings files in class library projects

I want to use a .NET settings file in an external dll library. This article explains exactly what I am trying to do.

partial class LastState
{
    public LastState() : base(new ConfigurationFileApplicationSettings("LastState.config", typeof(LastState))) { }
}

Unfortunately, using this implementation, it is not possible to save settings back to the config file. If I try to use Save() , SetPropertyValues throws a NotSupportedException. Is there any way to save a .NET settings file from an external dll library?

I would use custom configuration files .

ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
configMap.ExeConfigFilename = @"d:\test\justAConfigFile.config.whateverYouLikeExtension";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel)

Have a look here for more détails.

You can save with

config.AppSettings.Settings["YourThing"].Value = "New Value";
config.Save(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM