问题
Greetings StackOverflow,
In past projects I've gotten used to using the Settings Designer in Visual Studio to make settings files. This has worked well in the past. In my latest project I have a desire to have multiple version, a.k.a. profiles, of the same Settings class, one with production/default values for all the properties and one with test values.
While in search to see if this is possible I noticed that in the XML for the Settings.settings file there are multiple hints that having multiple setting profiles might be possible. For instance in the Settings.settings file the <SettingsFile>
tag has a CurrentProfile
attribute which is always set to CurrentProfile="(Default)"
. Inside of that tag there is an empty tag called <Profile />
. Lastly the <Value>
tag for each setting has a Profile
attribute that usually shows Profile="(Default)"
.
Now, I've tried looking to what the <Profile />
tag is all about and whether I can use it for something but none of my searches have come up with anything.
Ultimately I want to know whether there is a way to have different profiles of the same Settings class, each with it's own default values, so that I can use it might show up like this in my code:
Properties.Settings defaultSettings = Properties.Settings.Default;
Properties.Settings testSettings = Properties.Settings.Test;
If anyone knows where to find the XML Schema for the settings file or if what I am asking for is possible please let me know.
回答1:
I use the Enterprise library to set up different configurations with different development environments. It takes a little getting used to, but there's a nice configuration tool that'll read the config files and display all of your app settings. You can create delta files for each environment you plan on working with. I added the Merge Configuration executable into a lib folder within the project and topped it of by adding some Build Events to do the merging upon build so that the files are automatically ready for deployment:
"$(ProjectDir)lib\MergeConfiguration.exe" "$(ProjectDir)web.config" "$(ProjectDir)lib\Delta_Dev.dconfig" "$(ProjectDir)Configurations\web.config-dev.config"
来源:https://stackoverflow.com/questions/11655378/using-properties-settings-default-and-setting-alternate-profiles