BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News AutoUpdater.NET: An Easy to Use Alternative to ClickOnce

AutoUpdater.NET: An Easy to Use Alternative to ClickOnce

Bookmarks

For applications distributed outside of the Windows Store, having an update mechanism is crucial. For roughly a decade ClickOnce was the standard approach used for .NET applications, but many still find it hard to customize and troubleshoot. So alternatives such as Ravi Patel’s AutoUpdater.NET were developed.

InfoQ: Many of our readers are familiar with using ClickOnce to publish updates. How does AutoUpdater.NET differ?

Ravi Patel: AutoUpdater.NET provides same flexibility in handling update procedure as ClickOnce does. It has even more features. AutoUpdater.NET uses following type of XML file that contains all the information about update.

<?xml version="1.0" encoding="utf-8"?>
<item>

    <!-- Users will see the text you write inside this title tag on title bar of update window when there is new update available. -->
    <title>Recommended update for My Application is available.</title>

    <!-- Write the latest version of application that is available right now inside this tag. AutoUpdater.Net reads this tag and compare it with current version of this application installed on users PC. -->
    <version>1.4.0.0</version>

    <!-- This tag contains download URL of the application update. -->
    <url>http://example.com/myapplicationsetup.exe</url>

    <!-- This tag contains download URL for the 64 bit version of the application. AutoUpdater.NET decides which URL to use based on if currently installed application version is 32 bit or 64 bit. If currently installed application is 32 bit then download URL in URL tag is used. -->
    <url64>http://example.com/myapplicationsetup64.exe</url64>

    <!-- This tag contains the URL of Change log web page. AutoUpdater.NET will show the contents of URL inside web browser control of Update window. -->
    <changelog>http://example.com/releasenotes.html</changelog>
</item>

Developer put this XML file on their server and call the Start method with URL of the XML file as parameter to start the Update procedure. Developer can call this method anywhere they like. Developer can also provide update reminder interval when user press the Remind Later button by setting LetUserSelectRemindLater to false and setting interval by providing value for RemindLaterTimeSpan

And RemindLaterAt fields. If Developer provides true value for LetUserSelectRemindLater then users will see the dialog that let them choose the update reminder interval.

InfoQ: What happens when the user presses Update?

Ravi: When user press Update button inside Update window AutoUpdater.NET starts downloading the appropriate application version using Download URL. When it finishes the download, it executes the downloaded installer to install the update. If Developer sets the OpenDownloadPage field value of AutoUpdater class to true then User will see Download Page of appropriate version in web browser.

InfoQ: Let’s say I wanted a more complex scenario, such as offering different versions depending on the user. I’m imagining rolling deployments or maybe tagging some users for beta testing. How would you implement that with AutoUpdater.NET?

Ravi: To handle more complex scenarios Developer can handle the update procedure himself/herself by subscribing to the ‘CheckForUpdateEvent’ of AutoUpdater class.

AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;

private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
{
    if (args != null)
    {
        if (args.IsUpdateAvailable)
        {
            var dialogResult = MessageBox.Show( string.Format(
                "There is new version {0} avilable. You are using version {1}. Do you want to update the application now?",args.CurrentVersion, args.InstalledVersion), @"Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (dialogResult.Equals(DialogResult.Yes))
            {
                try
                {
                    // Developer can also use Download Update dialog used by AutoUpdater.NET to download the update.
                    AutoUpdater.DownloadUpdate();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        else
        {
            MessageBox.Show(@"There is no update avilable please try again later.", @"No update available", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
    else
    {
        MessageBox.Show( @"There is a problem reaching update server please check your internet connection and try again later.", @"Update check failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

Like as you mention the example of providing beta updates to only beta testers. You need version policy that differentiate Beta from stable release. Like if Update version is like 1.4.0 then its stable, but if it contains version like 1.4.0.2 then its beta 2 of version 1.4. Also You need to provide the check box in settings screen to opt in for beta version. When u handle the event u get the Current Version and Installed Version. If user is right now in beta version or opt in for beta releases then you can check if the current available version is beta by checking the minor version of Current Version and if its beta and user is beta user then you can Update the application.

Developers can also customize the library themselves by downloading the source code. I made the source code easy to understand even if Developer is beginner in .NET development.

AutoUpdater.NET is available under the Microsoft Public License (Ms-PL).

To suggest other open source projects that should be highlighted on InfoQ, contact Jonathan Allen at jonathan@infoq.com.

Rate this Article

Adoption
Style

BT