views:

23

answers:

2

I have a .settings file (containing both User and Application settings) that I would like to contain different values if built in Debug mode. Is there a supported or recommended way to do this?

+1  A: 

I use two separate config files for each mode. I copy the files into the BIN folder in the POST-BUILD event.

Raj More
+1  A: 

The Settings.Designer.cs file doesn't contain values, only application setting property declarations. The values are stored separately. Application setting values go into the app.exe.config file, user scoped setting values go in an appdata folder that has a name generated by a hashing algorithm. You'd only have trouble with the latter. Shouldn't matter, the file won't exist when you deploy your Release build to a machine.

In case you mean "can I change the default value" then the answer is: not when you use the settings designer. You'll have to move the setting into a separate class. Make it look similar to this:

using System;
using System.Configuration;
using System.Diagnostics;

namespace ConsoleApplication1.Properties {
    internal partial class Settings {
        [UserScopedSetting, DebuggerNonUserCode]
#if DEBUG
        [DefaultSettingValue("debug value")]
#else
        [DefaultSettingValue("release value")]
#endif
        public string Setting {
            get {
                return ((string)(this["Setting"]));
            }
            set {
                this["Setting"] = value;
            }
        }

    }
}

Make sure the namespace name matches the one used in the Settings.Designer.cs file and that you delete the setting from the Settings page.

Hans Passant