Andrei Smolin

Updating Office COM add-ins automatically

To test the example described below, click this link, download and run the application installing the sample COM add-in. When the add-in is installed, you start Excel 2000 – 2016 and find the add-in in the UI. Leave Excel open and in a couple of minutes, you’ll get a notification suggesting installing an update. Click Update and get the new add-in version installed. Below I describe creating and deploying such an add-in.

Add-in Express for Office and .NET version 8.7 extended the ClickTwice custom deployment technology with the Automatic Update feature. I’m going to describe several examples demonstrating the feature.

I’ll start with exploring Automatic Update’s default behavior. To demonstrate it, I create a basic COM add-in supporting Excel. The add-in creates a Ribbon label showing the add-in’s version. No other code.

Designing the add-in Ribbon UI

private void AddinModule_OnRibbonBeforeCreate(object sender, string ribbonId) {
        this.adxRibbonLabel1.Caption =
            "Current version: " +
            System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
    }

The add-in Ribbon UI at the run time

The add-in is signed with an Add-in Express certificate.

Signing the add-in

Now I create a setup project. I use the Add-in Express setup project wizard to create a Visual Studio Installer project; WiX and InstallShield are supported as well.

The setup project wizard

The next step is to build the setup project and publish the installer. I follow the steps described in the Add-in Express manual: create a setup project and build it, open the Publish dialog, specify the installer to publish and set preferences. Find more details below.

The default Automatic Update settings are as follows:

The default Automatic Update settings

The default settings of the updater application are:

The default settings of the Updater application

Here are the remaining parameters required for publishing: the installer to publish, the location where to put prepared files, the URL where to look for updates. I’ve specified an icon to be used by the updater application, and signed the installer:

The Publish dialog

If you click Publish, Add-in Express shows a warning: You’ve chosen to sign adxloader.dll.manifest. You should also select the "Sign ‘version_info.xml’ file" check box; see Preferences.

Set Sign ‘version_info.xml’ file as recommended, and click Publish again to get all the files prepared. The final step of publishing the initial add-in version is this: upload the version_info.xml file and folders from the MSIPublish folder (see your add-in project folder) to the location which is accessible for an end user via the URL specified in the Publish dialog (see the Installation URL field in the screenshot above):

The folder structure created when publishing the add-in

Provide an end user with a link pointing to the downloader. In this example, this link is http://cdn.add-in-express.com/samples/automatic-update/per-user-all-defaults/0/1.0.0/automaticupdatesexample_peruseralldefaults.exe. Note how the link points to a location within the folder structure.

When you click the link, the browser downloads the downloader. When run, the downloader downloads the MSI file:

The downloader progress form

When the MSI is downloaded, the downloader starts it:

The installer is started

You follow the on-screen instructions to get the add-in installed. Start Excel to find the add-in there:

The add-ins shows its Ribbon UI

Starting the add-in also starts the updater; check the Details tab of the Task Manager window.

If you prepare another version of the add-in, create a new (or modify existing) setup project, publish it and put the files to the location that the user can access via the URL specified in the Installation URL field, the updater finds the update and shows a Windows notification:

The notification window informing about version 2 available

Clicking the notification shows the updater’s form:

The updater application

Click Update. This downloads the update:

The updater downloads version 2

When the process is complete you get this message:

The updater requires to close the add-in's host application

Click Yes and close Excel. When Excel is closed, the updater starts the installer of version 2. When the installation is complete, Excel starts with the add-in’s version 2 loaded:

Add-in version 2 shows its Ribbon UI

6 Comments

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

    Hi,
    I want to Update Office COM add-ins automatically in my Excel add-in.
    For this, I need to Add-in Express certificate. How can get this certificate? please tell me about 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 Shyam,

    You are wrong; there’s no Add-in Express certificate.

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

    Hi,
    I want to update Office COM add-in without closing the office application. is this possible?

    Regards,

    Nitin Jain

  • 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 Nitin,

    To replace the add-in you need to replace the add-in DLL. But that file is locked by Office while the add-in is loaded. And Office doesn’t provide a way to unload it. Whence the need to restart the host application.

    That is, the answer is No, this isn’t possible.

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

    Hi Andrei,

    I don’t want to replace the Add-in DLL. here is my structure

    Com Add in
    Base Library
    Function Library

    Com Add in got the reference of base library and base library invokes the function library using reflection. Now Com Add in and base library is installed and we rarely updates it. (installer change). we usually updates the Function Library which gets downloaded in users roaming folder.

    Now the requirement is as soon as the function library version 2 gets downloaded, we need to tell our com add in or base library to use function library 2 instead of function library 1

    hope this is clear now.

    Regards,

    Nitin Jain

  • 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 Nitin,

    Add-in Express implements the logic I described above; that is, it expects that you replace the add-in DLL. You can experiment with replacing your other DLLs on the fly and invent an update schema to meet your requirements.

    Below I assume you have an executable that orchestrates the update process.

    The very first thing to check is: whether replacing the dependent DLL is possible? If it is possible to replace the DLL (meaning the DLL file is not locked) you can invoke a public method defined on the add-in module to let your add-in re-load the new version of the DLL. If the file is locked, try to turn the add-in off. If this doesn’t help, your only way is to restart the host application.

Post a comment

Have any questions? Ask us right now!