Settings.settings file saves Reset

When debugging my project in Visual Studio 2008, my Settings.settings file continues to receive reset between assemblies. Is there any way to prevent this?

Thanks.

+7
c # visual-studio-2008
source share
4 answers

Well, I found out the answer I was really looking for. Basically, you need to call LocalFileSettingsProvider.Upgrade. However, since I will deploy using ClickOnce, it will do this automatically for you.


Q: Well, but how do you know when to call Upgrade?

A: Good question. In Clickonce, when you install a new version of your application, ApplicationSettingsBase will detect it and automatically update the settings for you when loading point settings. In cases not related to Clickonce, there is no automatic update - you need to call Upgrade yourself. Here is one idea for determining when to call Upgrade:

Have a boolean parameter called CallUpgrade and set its default value to true. When your application starts, you can do something like:

if (Properties.Settings.Value.CallUpgrade) { Properties.Settings.Value.Upgrade(); Properties.Settings.Value.CallUpgrade = false; } 

This ensures that Upgrade () is called only when the application is first launched after the new version is deployed.

REF: http://blogs.msdn.com/rprabhu/articles/433979.aspx

+12
source share

I believe that Settings.settings files are saved based on the current version number, mainly as a β€œfunction”, where settings are not saved between different versions of the same program on the machine. Assuming that you automatically increase the version number when compiling (1.0. * In AssemblyInfo.cs), you will reset the settings each time you compile a new version.

To fix this, the best option would be to serialize your own settings file in the application data directory.

+2
source share

At the top of my head, I think you can set the "do not copy" option in the file properties (in Visual Studio with the right mouse button, Properties) when the project was built / launched. What happens is probably when your project is built, the settings file is copied to the bin debug directory, overwriting the settings file from the previous run.

0
source share

Among other reasons, the settings file continues to get reset every time you debug simply, because the next time you debug Debug, you can test the entire application again and again. Failure to reset the settings may result in undetected errors.

0
source share

All Articles