.NET Framework Bookmark and Share   
 index > MSBuild > How to migrate application setting during version upgrade
 

How to migrate application setting during version upgrade

Hi,
I'm using automatic versioning in the AssemblyInfo sothe assembly versionchanges over time. Then I found that theuser setting is specifically bound to a version, so each time the version upgrades, all the user setting is gone. There is a Upgrade() method that seems can migrate settings to a new version. But I don't have luck with it either as after calling it, my last saved settings are gone and it always present me with a set of settings I have no idea where it cames from.
So my question is what should I do with the user settings when version changes. Basically I want to migrate them all.
Thanks.
Daniel
Daniel_ngn

To achieve this,firstly add a bool value name "FirstRun" in the settings designer and initialize it as True, then program like following:

if(Properties.Settings.Default.FirstRun)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.FirstRun=false;
Properties.Settings.Default.Save();
}

I think you could handle it.


Please mark the replies as answers if they help and unmark them if they provide no help.
  • Marked As Answer byDaniel_ngn Friday, January 23, 2009 7:25 AM
  •  
Wesley Yao

Hello Daniel,

It seems to be a VSProject setting issue.

Can I move it toMSBuildor Visual C# IDEforum?

Thanks.


Please mark the replies as answers if they help and unmark them if they provide no help
Hua Chen
Yes Please. Thanks!
Daniel
Daniel_ngn

Hi, Daniel

You are using AssemblyInfo for updating the information of your application automatically, it’s cool. But I think the AssemblyInfo.cs takes no responsible for the user settings. Your application should save the user setting in the registry or a config file, or other ways. After every updating, reading the last setting from them could be a normal way to migrate the user setting. I don’t know how do you save the settings in your application, could you please provide some information about that? there should be something strange in the process that cause the problem.

About ?/span>it always present me with a set of settings? I think they should be some default values that are set in you code somewhere when the update occurs, so I suggest firstly to find out this place and see the logic.

If I misunderstood your meaning, or something unclear, please feel free to point it out.

Sincerely!


Please mark the replies as answers if they help and unmark them if they provide no help.
Wesley Yao
Thanks Wesley.
I save settings with the User Setting facility provided by .net framework, specifically, the default setting provider in the project Properties.
I navigated to the folder where .net actually store the user setting and the folder is version specific (like 1.0.0.0).
I don't really want to build a setting persistence on my own, but just can't figure out how to keep the settings across version.
Daniel
Daniel_ngn

Hi, Daniel

I think you could debug the code to see does the Upgrade() method work or not, if it works, then find out what it did for the configuration, as I know, this method try to match the two setting class in the two versions, and then update the corresponding setting values to the .config file. If it did nothing since the big modification in the new setting class, perhaps you have to override it, get the last setting value and configure them manually.

For more solution, hope the follow links can help you to handle it out.

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

http://www.codeproject.com/KB/dotnet/user_settings.aspx

About the Upgrade():

http://msdn.microsoft.com/en-us/library/system.configuration.applicationsettingsbase.upgrade.aspx

Sincerely!


Please mark the replies as answers if they help and unmark them if they provide no help.
Wesley Yao
The Upgrade() method is definitely doing something, but my situation is if I call this method, my latest usersettings won't get applied, instead, it will come with a piece of setting I have no idea where it comes from. So each time after I call this, settings are set to the same value (not the default value, neither the value I saved last time). If I don't call this method, it works fine when version doesn't change, otherwise every setting is reset to default value. Any idea what's going on here? Thanks.


Daniel
Daniel_ngn

Hi, Daniel

Thanks for your feedback.

I did a test in a small console application, following are the steps:

1. Uncomment the AssemblyVersion("1.0.*")] and Comment [assembly: AssemblyVersion("1.0.0.0")] in AssemblyInfo.cs.

2. Add a setting “TestText”—String—User--"InitialText?in the setting designer.

3. Code like below:

Properties.Settings.Default.Version="changed";
Properties.Settings.Default.Save();
Console.WriteLine("Theversionis{0}",Properties.Settings.Default.Version);

Run this code and the result is: “The text is: ChangedText?

4. Change the code like below:

//Properties.Settings.Default.TestText=“ChangedText?
//Properties.Settings.Default.Save();
Console.WriteLine(“Thetextis:{0}?Properties.Settings.Default.TestText);

Of course this time the result is: “The text is: InitialText?

5. Change the code like below:

//Properties.Settings.Default.TestText=“ChangedText?
//Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Console.WriteLine(“Thetextis:{0}?Properties.Settings.Default.TestText);

At this time, the result is: “The text is: ChangedText? the Upgrade() works well.

I don’t know what’s your code logic looks like, and I assume, maybe somewhere in your code change the settings but forget to use Save(), because the Upgrade() revert the settings to the last saved values, so the application give you a set of strange settings that you make no sense about them, and they were saved inanold version. Without looking your code, I just guessing around, hope can help you.

Sincerely!


Please mark the replies as answers if they help and unmark them if they provide no help.
Wesley Yao

Thanks Wesley, the behavior at my side is exactly the same as yours.

However, to reproduce my issue, you'll have to leave the Upgrade() call alwaysthere and then try changing the setting, then you may find that the changed setting can't be applied next time the app starts.

It looks like the Upgrade() method will always try to load the setting from a previous version. So how could I know when to call this method when starting off my app? Ideally it should be the first time I start the new version ofmy app, but how could I know it's the first time?

Thanks!


Daniel
Daniel_ngn

To achieve this,firstly add a bool value name "FirstRun" in the settings designer and initialize it as True, then program like following:

if(Properties.Settings.Default.FirstRun)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.FirstRun=false;
Properties.Settings.Default.Save();
}

I think you could handle it.


Please mark the replies as answers if they help and unmark them if they provide no help.
  • Marked As Answer byDaniel_ngn Friday, January 23, 2009 7:25 AM
  •  
Wesley Yao
Hi Wesley,

I just want to drop a note to thank you for the simple method to address the issue. It works very well for my application.
hz
hipswich

You can use google to search for other answers

Custom Search

More Threads

• AssemblyInfoTask: Problem with comments?
• standalone cdrom applications
• What is Homesite
• Recursive excludes
• Trigger ms build from inside visual studio build (c++ project)
• How to create an attribute that will add build warning to users of a method/property
• vcbuild usage question
• What is the definition for MSB6006?
• VFP9 and MS Build
• ItemGroup and copy files behavious