Pieter van der Westhuizen

How to implement auto-update for Office add-ins

Automatic updates for software applications’ mobile apps have become an everyday occurrence for most users. For a user it provides a level of comfort to know that their software is always up to date with the latest and greatest version. It could also be a source of irritation for many users depending on the frequency of updates – not many users would be happy upgrading to a new version every day.

Of course, Office Add-in is no exception and it is also necessary to deploy a new version of your add-in from time to time.

Add-in Express deployment options

Add-in Express for Office and .net provides two options for deploying your Office add-ins:

  • ClickOnce, which allows users to install any Windows based application by clicking a link on a web page. ClickOnce technology has been an option for developers since .NET Framework 2.
  • ClickTwice, which is a deployment technology developed by Add-in Express that allows developers to combine the ease of deployment and auto updating of ClickOnce with the power and flexibility of MSI based installers.

Checking for updates with ClickOnce

For this example, we’ve created a simple MS Excel add-in that adds a custom ribbon tab to the Excel Ribbon.

A simple Add-in Express based Excel add-ins that adds a custom ribbon tab to the Excel Ribbon

Add the following code to the “Check for Update” button’s OnClick event:

private void adxRibbonButtonCheckForUpdate_OnClick(object sender,
    IRibbonControl control, bool pressed)
{
    if (this.IsNetworkDeployed())
    {
        this.CheckForUpdates();
    }
}

The IsNetworkDeployed method is available on every Add-in Express module and return True when the add-in was installed using ClickOnce. The CheckForUpdates method starts the process of checking for a new version of you add-in.

With the code in place we’re ready to build a ClickOnce installer for our add-in. In order to create a ClickOnce installer, right-click on the project inside the Solution Explorer and select Publish ADX Project.

Creating a ClickOnce installer

This will show the Publish dialog window. Click the Populate button to automatically detect the necessary files to deploy for your add-in. Next, set your Provider URL. In this scenario we’ll point it to a local folder and finally either select or create a new certificate file. Lastly, make sure to specify the Minimum required version which in this case is 1.0.0.0

Configuring a ClickOnce installer options

Click the Publish button and your add-in will be published to a Publish folder inside your project’s folder.

Since we set our provider URL to C:\Temp\Published\clickonceupdate.application we should copy the files that were built to the Publish folder, to the C:\Temp\Published folder. The folder layout should resemble the following:

The Published folder content

To install the add-in you simply need to double click the .application file. This will launch the installer and display the following dialog:

The Launching Application dialog

After the requirements have been verified, the application install dialog will be displayed, where the user has to click Install in order to start the installation of your Office add-in.

The user has to click Install in order to start the installation of the add-in.

After the installation, you should see our “My Add-in” Ribbon Tab when starting Excel.

The custom Excel ribbon tab shows up on Excel start

At this stage, when clicking the Check for Update button on our custom Excel Ribbon Tab, the add-in will not find a new version, which means no automatic update for your Excel add-in is available so far.

We’ll need to update our add-in’s version number and publish it again in order to detect a newer version. To do this, switch back to our project in Visual Studio, right click on the project name and select Properties from the context-menu. Click on the Assembly Information… button and update the Assembly version number to 2.0.0.0

Updating the add-in's version number

Rebuilt and publish your add-in project. This time update the minimum required version to 2.0.0.0

Copy the files in the Publish folder to the path we specified in the Provider URL. Make sure to replace the .application and setup.exe files. You’ll also notice that a new folder has been added called 2.0.0.0

A new folder called 2.0.0.0 has been added to the Published folder

Open Excel and click on the Check for update button. The latest update should be detected and you will be presented with the following form:

The latest update is detected.

The auto update will complete and you will be prompted to close Excel in order to finalise the update process.

The user is prompted to close Excel in order to finalise the update process.

A notification will be displayed informing the user that the automatic update and add-in registration was successful.

A notification informs the user that the auto update and add-in registration were successful.


Checking for updates with ClickTwice :)

ClickTwice :) is a technology developed by Add-in Express that allows developers to deploy their Office add-ins’ MSI installers over the internet. In essence it combines the ease of deployment of ClickOnce with the power and flexibility of MSI installers.

To check for updates using ClickTwice :) we first need to change the code in our add-in to check whether there is an MSI update available. Open the OnClick event handler code for the Check for Update button and change the code to the following:

private void adxRibbonButtonCheckForUpdate_OnClick(object sender,
    IRibbonControl control, bool pressed)
{
    if (this.IsNetworkDeployed())
    {
        this.CheckForUpdates();
    }
 
    if (this.IsMSINetworkDeployed() && this.IsMSIUpdatable())
    {
        string updatePath = this.CheckForMSIUpdates();
        if (!string.IsNullOrEmpty(updatePath))
        {
            if (MessageBox.Show(
                "A new version for this add-in is available. Would you like to update this add-in?",
                "New version available", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
            {
                Process.Start(updatePath);
            }
        }
    }
}

In the code above we’ve checked whether the add-in was deployed using MSI by checking whether the IsMSINetworkDeployed property is true. We also checked whether the user is allowed to update the application by checking whether the IsMSIUpdateable property is true.

The CheckForMSIUpdates method is invoked and will return a string containing the URL or path to the update file. If an empty string is returned, it means there is no auto-update available for the add-in.

Next, create a new setup project for our Office add-in by right-clicking on our project inside the Visual Studio Solution Explorer and selecting Create Setup Project.

Creating a new setup project for the Office add-in

This will launch the New Setup Project wizard. You have a choice to use either InstallShield or WiX to build your setup project and the standard Visual Studio Installer if you’re using Visual Studio 2010 or earlier.

The New Setup Project wizard

In this example, we’ll use WiX. Complete the wizard and build the newly created setup project. After the setup project has been built, right-click on the add-in project and select Publish ADX Project.

Right-click on the add-in project and select Publish ADX Project to open the Publish dialog.

Click on the MSI-based web deployment tab and select the Installer file (.msi). Also, specify the publishing location, which can be either a file path or an URL. Lastly, either select or create a new certificate file and click Publish.

The files will be published to the publishing path, and you’ll see the following files/folders in the Publish folder:

The files/folders contained in the Publish folder

The language code folder (1033) will contain a folder for each version of the setup. Install the add-in by running the .exe file inside the 1.0.0.0 folder. This will launch the ClickTwice :) updater, which in turn will download and run the .msi file. Finish the installation and you should see your add-in inside Excel.

Next, switch back to Visual Studio and update the Version number inside the Wix setup file (.wxs) to 2.0.0.

<Product
  Id="071f57a4-bbd4-420f-9df5-28fbb4d866ae"
  Name="ClickOnceUpdate"
  Language="1033"
  Version="2.0.0"
  Manufacturer="Add-in Express"
  UpgradeCode="071f57a4-bbd4-420f-9df5-28fbb4d866af"
  Codepage="1252"/>

Make any changes to your add-in that you require for version 2 and build the project. You should also rebuild the setup project in order to update the .msi file. Publish the add-in, and you’ll notice that it has detected the new version number.

The wizard has detected the new version number.

Now that our add-in is ready for auto-updating, all that remains to do now is to switch back to Excel and click on the Check for Updates button. Our code will execute and inform the user that a new update is available.

Switch back to Excel and click on the Check for Updates button.

The ClickTwice :) update will run and the user will be prompted to close Excel before the installation can complete. After the user closes Excel the MSI installer will automatically run.

When Excel is started, the user should see that the addin automatically got updated to the new version. In the same manner, you can build in auto-updating for an Outlook plug-in, Word or PowerPoint add-in, etc.

Thank you for reading. Until next time, keep coding!

Available downloads:

This sample Excel add-in was developed using Add-in Express for Office and .net:

Auto-updating sample add-in for Excel

You may also be interested in:

4 Comments

  • https://secure.gravatar.com/avatar/6042e63c507f0adc124a15f64d4790f0?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G gerald says:

    please fix the link. I’m getting 404 Not Found when trying to download the sample add-in

  • https://secure.gravatar.com/avatar/29957f26ad2d8ba527fd9cc8cfa7b2e0?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Andrei Smolin (Add-in Express Team) says:

    Thank you for pointing! Please check if the link works for you now.

  • https://secure.gravatar.com/avatar/3e75389d4edfc8f59c55ec4c41e03811?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Thomas Darde says:

    Latest release (october 2016) says “supprt for automatic updates in clicktwice deployment” in the release note
    Where can I find more information on this ?

  • https://secure.gravatar.com/avatar/29957f26ad2d8ba527fd9cc8cfa7b2e0?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Andrei Smolin (Add-in Express Team) says:

    Hello Thomas,

    Please check section Automatic Updates, see the PDF file in the folder {Add-in Express}\Docs on your development PC.

Post a comment

Have any questions? Ask us right now!