Search code examples
visual-studioapplication-settings

how to access local visual studio app settings?


I originally asked this thinking updated settings weren't being saved, but that was the wrong question.

I see updated settings are in AppData/..user.config, which is pretty much where docs suggest they should be, but...

I had been trying to access since "Properties.Settings.Default,MySetting", but that is a different file, and Properties.Settings["MySetting"] doesn't work either. The docs.suggest that my local user.config values should override the default values in app.config, but that isn't working for me.

How do I access updated values from user.config??

Cheers,
Berryl

the setting

    [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;
        }
    }

the update code

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

Solution

  • I did not find an easy answer to this, although I suspect it involves writing a custom SettingsProvider class.

    My issue involves a few settings related to testing, which needed to be accessed from both the executable and my test runner (hence the different local user.config files). I just wrote a small class to maintain a dictionary of the settings I need and serialize/deserialize it from a known location. Seems like something should be available to do this easier (and which is quick to grok), but I haven't found it yet.

    Cheers,
    Berryl