【问题标题】:.NET settings files in class library projects类库项目中的 .NET 设置文件
【发布时间】:2015-03-10 05:37:12
【问题描述】:

我想在外部 dll 库中使用 .NET 设置文件。 This article 准确地解释了我想要做什么。

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

不幸的是,使用此实现,无法将设置保存回配置文件。如果我尝试使用Save(),SetPropertyValues 会引发 NotSupportedException。有没有办法从外部 dll 库中保存 .NET 设置文件?

【问题讨论】:

    标签: c# wpf application-settings


    【解决方案1】:

    我会使用custom configuration files

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

    查看here了解更多详情。

    你可以保存

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-18
      • 2011-05-26
      • 1970-01-01
      • 2022-08-07
      • 1970-01-01
      • 2021-11-05
      • 2010-10-29
      • 1970-01-01
      相关资源
      最近更新 更多