简体   繁体   English

"如何防止在每次新安装后重置 settings.settings 文件"

[英]How to prevent settings.settings file reset after each new installation

So I have WPF application and I am using settings.settings file to save several settings for example specific Path that the user need to set and I am also create a exe installation file using Advanced installer and after install new application version all the application files (include the application exe file) replaced with the new version and in such case all settings.settings variables reset and I want to prevent it.所以我有WPF application ,我正在使用settings.settings文件来保存几个设置,例如用户需要设置的特定Path ,我还使用Advanced installer创建一个exe安装文件,并在安装新的application版本后所有应用程序文件(包括应用程序exe文件)替换为新版本,在这种情况下,所有settings.settings变量都会重置,我想阻止它。

Any ideas ?有任何想法吗 ?

If I understand correct, when you upgrade your application you want your settings.settings file to be saved.如果我理解正确,当您升级应用程序时,您希望保存 settings.settings 文件。 If you don't want to use "Side by side install", you can do this:如果您不想使用“并排安装”,您可以这样做:

  1. On install time, from AI, add a "New File Operation" and copy your file to an backup folder for example.例如,在安装时,从 AI 中添加“新文件操作”并将文件复制到备份文件夹。<\/li>
  2. Now you need to copy back your file when the new application is installed.现在您需要在安装新应用程序时复制回您的文件。 You need to add a script with custom action with sequence (Launch file for .bat, or PowerShell inline script).您需要添加带有序列的自定义操作的脚本(.bat 的启动文件或 PowerShell 内联脚本)。 You can do that with .bat or PowerShell.您可以使用 .bat 或 PowerShell 来做到这一点。 I recommend you .bat since is more easy.我推荐你 .bat 因为更容易。 Configure this custom action to be be executed "When the system is being modified (deferred)", check "Run under the LocalSystem account" and also on "Execution Stage Condition" select only "Install".配置要执行的自定义操作“当系统被修改(延迟)时”,选中“在 LocalSystem 帐户下运行”,并且在“执行阶段条件”上只选择“安装”。 You can find how to copy files in .bat on google, it's something with xcopy \/Y %1 %2<\/code>您可以在 google 上找到如何在 .bat 中复制文件,这是xcopy \/Y %1 %2<\/code><\/li><\/ol>

    If this is what you need and you can't implement it, just tell me and I will try to help you.如果这是您需要的,但您无法实施,请告诉我,我会尽力帮助您。

    "

For Windows Forms apps I use code like this in my main form, after the call to InitializeComponent().对于 Windows 窗体应用程序,在调用 InitializeComponent() 之后,我在主窗体中使用这样的代码。 It copies the settings from the previous version the first time the new version runs.它会在新版本第一次运行时复制以前版本的设置。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM