Squirrel.Windows: Inconsistent config file after update.

I update my app with Squirrel and I call RestartApp().

Since the old installation folder is left intact and a new one is created inside the rootAppDirectory, the config file is written from scratch. As a result, any settings retained in the old installation’s config file, don’t migrate to the new config file. This is a problem if the app makes use of Properties.Settings to keep application settings.

I should either create some logic myself to port the settings I want to the new config file, or dump the Application settings and use a custom settings file, probably saved in AppData\MyAppData.

Am I missing something?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 19 (7 by maintainers)

Most upvoted comments

Indeed you can use the methods below to backup your settings, typically just after your update has completed, so just after your call to await mgr.UpdateApp(); You want to restore them at the very beginning of your program, like just after Squirrel’s event handler registration. Don’t try doing a restore from the onAppUpdate it won’t work. By the look of it onAppUpdate is executing from the older app process as it would not get access to the newer app data folder.

    /// <summary>
    /// Make a backup of our settings.
    /// Used to persist settings across updates.
    /// </summary>
    public static void BackupSettings()
    {
        string settingsFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
        string destination = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\..\\last.config";
        File.Copy(settingsFile, destination, true);
    }

    /// <summary>
    /// Restore our settings backup if any.
    /// Used to persist settings across updates.
    /// </summary>
    private static void RestoreSettings()
    {
        //Restore settings after application update            
        string destFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
        string sourceFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\..\\last.config";
        // Check if we have settings that we need to restore
        if (!File.Exists(sourceFile))
        {
            // Nothing we need to do
            return;
        }
        // Create directory as needed
        try
        {
            Directory.CreateDirectory(Path.GetDirectoryName(destFile));
        }
        catch (Exception) {}

        // Copy our backup file in place 
        try
        {
            File.Copy(sourceFile, destFile, true);
        }
        catch (Exception) {}

        // Delete backup file
        try
        {
            File.Delete(sourceFile);
        }
        catch (Exception) {}

    }

Agreed, this is the best solution I have found for using Properties.Settings with Squirrel. Thanks, @Silon. One thing I had to be sure to do after calling RestoreSettings() is make a call to Properties.Settings.Default.Reload() before attempting to use any of the settings.

I just implemented @Slion’s solution in Visual Basic. The translation was straightforward. Its a very simple and slick way to solve the problem.

Indeed you can use the methods below to backup your settings, typically just after your update

Wow, thanks for this. Worked perfectly for me. Although, like others have said, after restoring the file you need to refresh settings.

Thanks, @Silon. I stumbled over this as well and used your solution. It has its pros and cons the way Squirrel installs an app. I understand the problem with have the same install folder, but have a new folder each time has it problems to.