Persisting app.config variables in updates via Click once deployment

旧巷老猫 提交于 2019-11-27 00:58:17

问题


Every time a new update is released for an application with click once, the variables in the app.config file are destroyed

<userSettings>
    <app.My.MySettings>
      <setting name="Email" serializeAs="String">
        <value />
      </setting>
      <setting name="UserName" serializeAs="String">
        <value />
      </setting>
    </app.My.MySettings>
  </userSettings>

How can i prevent that?

Is there any way of feching the variables from the previous application version?


回答1:


Do you have the "Applications should check for updates" option checked?

Have a look at Exploring Secrets of Persistent Application Settings (the section titled "Maintaining Settings Between Program Versions"):

For any settings from the current version that match settings in the prior version, this routine will import them into the current version's user.config file:

At the entry point to your program, place the following code.

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

Note that UpgradeSettings is a boolean user setting (not application) that you need to add yourself, and you want the default value to be True.




回答2:


If you use user-level settings instead of application-level settings, it will copy them forward when a new version is retrieved. The safest thing to do, though, is to separate this data from the ClickOnce update, uh, "experience". See if this helps:

http://robindotnet.wordpress.com/2009/08/19/where-do-i-put-my-data-to-keep-it-safe-from-clickonce-updates/



来源:https://stackoverflow.com/questions/622764/persisting-app-config-variables-in-updates-via-click-once-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!