Squirrel.windows: Restart immediately after update

Created on 12 Aug 2015  路  5Comments  路  Source: Squirrel/Squirrel.Windows

Hi,

We are trying to move away from ClickOnce to Squirrel. We need the new version of the application to run immediately. and I'm trying the below code:

Task.Run(async () =>
{
using (var mgr = new UpdateManager(@"", "AssetteDeploymentTest"))
{
var updateInfo = await mgr.CheckForUpdate();

                if (updateInfo.CurrentlyInstalledVersion.SHA1 != updateInfo.FutureReleaseEntry.SHA1)
                {
                    MessageBox.Show("<Show some message about update");
                    await mgr.UpdateApp();
                    UpdateManager.RestartApp();

                }
            }
        });

The above still restarts the older version. how can we start the new version immediately.

Most helpful comment

Unless I'm missing something I guess this has been fixed along the way as simply calling RestartApp() works for me. (Squirrel.Windows v1.5.2).

        // Check for Squirrel application update
        ReleaseEntry release = null;
        using (var mgr = new UpdateManager("http://publish.slions.net/MonitorConfigDemo"))
        {
            //
            UpdateInfo updateInfo = await mgr.CheckForUpdate();
            if (updateInfo.ReleasesToApply.Any()) // Check if we have any update
            {
                System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);

                string msg =    "New version available!" +
                                "\n\nCurrent version: " + updateInfo.CurrentlyInstalledVersion.Version +
                                "\nNew version: " + updateInfo.FutureReleaseEntry.Version +
                                "\n\nUpdate application now?";
                DialogResult dialogResult = MessageBox.Show(msg, fvi.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    // Do the update
                    release = await mgr.UpdateApp();
                }
            }
        }

        // Restart the app
        if (release!=null)
        {
            UpdateManager.RestartApp();
        }

All 5 comments

I faced this issue too. I solved it like this. A pragmatic approach but works.

bool restart = false;
string latestExe = "";

using (var mgr = new UpdateManager(updatePath, packageName))
{
    var updates = await mgr.CheckForUpdate();
    if (updates.ReleasesToApply.Any())
    {
        var lastVersion = updates.ReleasesToApply.OrderBy(x => x.Version).Last();

        await mgr.DownloadReleases(updates.ReleasesToApply);
        await mgr.ApplyReleases(updates);

        latestExe = Path.Combine(mgr.RootAppDirectory, string.Concat("app-",lastVersion.Version.Major,".", lastVersion.Version.Minor, ".", lastVersion.Version.Build, ".", lastVersion.Version.Revision), "Your.exe");
        restart = true;
    }
    else
    {
        //No updates
    }
}

if (restart)
{
    UpdateManager.RestartApp(latestExe);
}

await mgr.ApplyReleases(updates); returns the path to the current version's folder, so you could use latestExe = Path.Combine(await mgr.ApplyReleases(updates), "Your.exe");

Thanks @lukee910.
latestExe = $"\"{Path.Combine(await mgr.ApplyReleases(updates), "Your.exe")}\""; for routes with spaces.

Unless I'm missing something I guess this has been fixed along the way as simply calling RestartApp() works for me. (Squirrel.Windows v1.5.2).

        // Check for Squirrel application update
        ReleaseEntry release = null;
        using (var mgr = new UpdateManager("http://publish.slions.net/MonitorConfigDemo"))
        {
            //
            UpdateInfo updateInfo = await mgr.CheckForUpdate();
            if (updateInfo.ReleasesToApply.Any()) // Check if we have any update
            {
                System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);

                string msg =    "New version available!" +
                                "\n\nCurrent version: " + updateInfo.CurrentlyInstalledVersion.Version +
                                "\nNew version: " + updateInfo.FutureReleaseEntry.Version +
                                "\n\nUpdate application now?";
                DialogResult dialogResult = MessageBox.Show(msg, fvi.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    // Do the update
                    release = await mgr.UpdateApp();
                }
            }
        }

        // Restart the app
        if (release!=null)
        {
            UpdateManager.RestartApp();
        }

Looks resolved from here. @shiftkey

Was this page helpful?
0 / 5 - 0 ratings