【问题标题】:how to access local visual studio app settings?如何访问本地 Visual Studio 应用程序设置?
【发布时间】:2011-07-10 15:23:38
【问题描述】:

我最初问这个问题时认为更新的设置没有被保存,但这是个错误的问题。

我看到更新的设置位于 AppData/..user.config 中,这几乎是文档建议的位置,但是...

自“Properties.Settings.Default,MySetting”以来我一直在尝试访问,但这是一个不同的文件,Properties.Settings["MySetting"] 也不起作用。 docs.suggest 我的本地 user.config 值应该覆盖 app.config 中的默认值,但这对我不起作用。

如何从 user.config 访问更新的值?

干杯,
浆果

设置

    [global::System.Configuration.UserScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Configuration.DefaultSettingValueAttribute("1970-01-01")]
    public global::System.DateTime CurrentWeekStartDate_SqlServer {
        get {
            return ((global::System.DateTime)(this["CurrentWeekStartDate_SqlServer"]));
        }
        set {
            this["CurrentWeekStartDate_SqlServer"] = value;
        }
    }

更新代码

            var setting = SqlServerTestDataDataGenerator.RunSqlServerTestDataFileGenerator();
            TestingSupport.Properties.Settings.Default.CurrentWeekStartDate_SqlServer = setting;
            TestingSupport.Properties.Settings.Default.Save();

【问题讨论】:

    标签: visual-studio application-settings


    【解决方案1】:

    我没有找到一个简单的答案,尽管我怀疑它涉及编写自定义 SettingsProvider 类。

    我的问题涉及一些与测试相关的设置,需要从可执行文件和我的测试运行程序(因此不同的本地 user.config 文件)访问这些设置。我刚刚写了一个小类来维护我需要的设置字典,并从已知位置对其进行序列化/反序列化。似乎 something 应该可以更轻松地做到这一点(并且很快就能理解),但我还没有找到它。

    干杯,
    浆果

    【讨论】:

      猜你喜欢
      • 2013-08-24
      • 1970-01-01
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多