Deploying a COM Addin in 64-bit Office

Deployment alone is a hassle for VSTO Developers, especially beginners. In this, if one needs to deploy add-in in a 64-bit system is hectic. Here is a simple solution that I have used to debug and deploy add-ins in 64-bit Office.

You just need to follow these steps.
By default, the add-in will be registered with the respective office application. This is enough to run the application in debug mode. If we select ‘my add-in should be available to all users…’ option, it registers the add-in in the 32-bit global registry. This can be seen in RegEdit like this.
HKLM\Software\Wow6432Node\Microsoft\Office\\AddIns\

But, 64-bit Office cannot see registries in this location. For the add-in to load correctly, the registry keys should be moved to the following location.
HKLM\Software\Microsoft\Office\\AddIns\

For deploying the application…

In Visual Studio 2010, you just need to update the TargetPlatform property to x64 in the Setup Project Properties. Your project is ready to be deployed in 64-bit versions of Office now!

If you are working on Visual Studio 2008, there is a bug in setup project which prevents the add-in from registering 64-bit COM components. A work around is suggested for this problem in Cannot load 64-bit self-registering DLL’s section in Troubleshooting Windows Installer Deployments article in MSDN. It describes how to manually write 64-bit registry keys for making your add-in to work in 64-bit Office.

For more details, go through this article: Deploying COM Add-ins for 64-bit Office using Visual Studio

Advertisements

Key points for updating a deployed office solution

You might have got a requirement to update the existing (deployed) office solution. If so, here are some key points related to signing certificates, that you need to keep in mind before doing this, which are suggested by msdn.

  1. Ensure that the solution is set up to provide the correct evidence for the security checks –
    • If the old solution is signed with a trusted certificate, sign the updated solution with the same certificate. If the certificate has expired or cannot be reused, use a certificate that is trusted at the enterprise level.
    • If the ClickOnce trust prompt was used for trust but the zone has been disabled, the solution will be disabled.
    • If the signing key was changed, trust must be re-established by using the ClickOnce trust prompt, or the certificate must be trusted at the enterprise level. If the trust is pre-established, the first version will be uninstalled and the updated version will be installed.
    • If the new certificate is trusted at the enterprise level, then the update takes place with no prompting.
    • If the new certificate is not trusted, a trust prompt is displayed to the user, if the prompt is allowed.
  2. Use the Publish Wizard to publish the updated Office solution to the same directory as the previous version.
    The Office solution is published to a folder at the same directory level as the old solution, but with an incremented version number. The application and deployment manifests are replaced, so the user is automatically directed to the new version the next time the solution checks for updates.
  3. Copy the solution files to the installation location, if it is different from the publish location. Keep the folders and files in the same relative positions.

Bootstrapper package for Office 2010 PIAs

Microsoft released Bootstrapper Package Installer for Office 2010 PIAs (Primary Interop Assemblies). This installer will add ‘Microsoft Office 2010 Primary Interop Assemblies‘ to the Prerequisites Dialog Box in Visual Studio 2008/2010. This will be useful to deploy Office PIAs with the addin when deployed with ClickOnce or Setup Project.

You can download the Bootstrapper Installer from the following link.

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=5d57c998-b630-4f38-afaa-b79747a3da06&displaylang=en

Check for appplication updates programmatically using ClickOnce Deployment

By default, ClickOnce provides two ways to update the application after installed in the client.

  1. Check everytime when the customization runs
  2. Check at regular intevals
ClickOnce Deployment Update Options

Default update types in ClickOnce Deployment

With the above, the user has to wait till it completes checking for the updates every time when the customization is loaded or at some time interval. It will be a waste of time for the users if application does not  update builds frequently.

How it would be if we provide a button for checking for updates when the user wish to do?

Hmm… Do you think that this is a headache process and hard to implement?

But, NO!

Here are the quick and simple steps to do this.

  1. Create a Windows Forms Application
  2. Place a button and call the following code. (It will check for updates and install them for you when the button is clicked)
Private Sub InstallUpdateSyncWithInfo()
    Dim info As UpdateCheckInfo = Nothing

    If (ApplicationDeployment.IsNetworkDeployed) Then
        Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment

        Try
            info = AD.CheckForDetailedUpdate()
        Catch dde As DeploymentDownloadException
            MessageBox.Show("The new version of the application cannot be downloaded at this time. " + _
                                       ControlChars.Lf & ControlChars.Lf & "Please check your network" + _
                                       "connection, or try again later. Error: " + dde.Message)
            Return
        Catch ioe As InvalidOperationException
            MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application." + _
                                      "Error: " & ioe.Message)
            Return
        End Try

        If (info.UpdateAvailable) Then
            Dim doUpdate As Boolean = True

            If (Not info.IsUpdateRequired) Then
                Dim dr As DialogResult = MessageBox.Show("An update is available. Would you like to " + _ 
                                                 "update the application now?", "Update Available", 
                                                 MessageBoxButtons.OKCancel)
                If (Not System.Windows.Forms.DialogResult.OK = dr) Then
                    doUpdate = False
                End If
            Else
                ' Display a message that the app MUST reboot. Display the minimum required version.
                MessageBox.Show("This application has detected a mandatory update from your current " & _
                    "version to version " & info.MinimumRequiredVersion.ToString() & _
                    ". The application will now install the update and restart.", _
                    "Update Available", MessageBoxButtons.OK, _
                    MessageBoxIcon.Information)
            End If

            If (doUpdate) Then
                Try
                    AD.Update()
                    MessageBox.Show("The application has been upgraded, and will now restart.")
                    Application.Restart()
                Catch dde As DeploymentDownloadException
                    MessageBox.Show("Cannot install the latest version of the application. " & ControlChars.Lf 
                                              & ControlChars.Lf & "Please check your network connection," + _ 
                                               " or try again later.")
                    Return
                End Try
            End If
        End If
        End If
End Sub

Now say, Ain’t this cool? 🙂

Reference: http://msdn.microsoft.com/en-us/library/ms404263.aspx

Hope this helps!

Common mistakes while installation and deployment of PIAs

Have you ever came across this error message while deploying PIAs along with your add-in as prerequisites?

Problem:

Error 1316: Setup cannot read from file {PATH}\PIARedist.MSI. Check your connection to the network, or CD-ROM drive. For other potential solutions, see SETUP.CHM.

Reason:

This error occurs if the PIA’s already installed in the client system. This usually happens with Office 2007 if Outlook is installed with Contact Manager.

Business Contact Manager for Outlook 2007 installs the PIAs by default, and the file name is PIARedist.MSI.  However, the file from the Microsoft Download Center is called o2007pia.msi.  When you install the PIAs from the Microsoft Download Center, this name conflict causes the 1316 error.

Solution:

The simplest solution is to just ignore the error, because this message means that the PIAs are already installed. If you want to correct the error, uninstall the PIAs through the list of installed programs for the specific computer. Then you can reinstall the PIAs with the Primary Interop Assemblies for the 2007 Microsoft Office system from the Microsoft Download Center.

For more details, refer to Misha’s article in her blog.

http://blogs.msdn.com/b/vsto/archive/2008/05/20/common-pitfalls-during-pia-deployment-and-installation.aspx

Including Custom Prerequisites in a Setup Project to install Hot Fix

Today I came across a discussion that is going on in MSDN Forums on the topic “How to check for a Microsoft Hot Fix in the client system and install if it is not installed in it?”. After going through the threads and reading few articles on this, I would like to share a quick work-around  for this problem which might help someone who is facing the same problem.

Briefly, the solution is to create a bootstrapper package for the required Hot Fix and use it as prerequisite in the Setup Project

We can create the bootstrapper using a tool called “Bootstrapper Manifest Generator” (BMG). This can be downloaded (free) from the following location.

http://code.msdn.microsoft.com/bmg

We can check registry to confirm whether the Hot Fix is installed or not. We need to set several Bypass-if conditions to make sure that we install the Hot Fix only when it is particular version of OS and the Hot Fix has not been installed.

* Usually Hot Fixes are Operating System specific

Here are some useful links related to this topic.

http://social.msdn.microsoft.com/forums/en-us/winformssetup/thread/58E75C92-4689-487E-9FF7-8835246B82FA

http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/a4e2a6af-c3ea-4b7a-9348-7dfa6a6164dd

Setting up bootstrapper package of Microsoft Office Primary Interop Assemblies (PIA) to use as prerequisite for setup project

This is the procedure to set Office Primary Interop Assemblies as prerequisites to your setup project.

First, You need to download the sample of component checker sample (ComponentChecker.cpp) from this MSDN page. http://msdn.microsoft.com/en-us/library/bb332051(office.12).aspx

Please go through “Preparing the Office Component Check” section in this article. Then follow these steps.

  1. Open the Command Prompt window needed to compile the check.If you are using Visual Studio 2008, open the Visual Studio 2008 Command Prompt by clicking Start, and then pointing to Programs, pointing to Microsoft Visual Studio 2008, pointing to Visual Studio Tools, and then clicking Visual Studio 2008 Command Prompt.
  2. At the command prompt, change the directory to {SamplesDir}\projects\Checks

    By default, the SamplesDir directory is C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample Version 3\.

  3. Compile the component checker by typing the following command
    cl.exe /Oxs /MT /GS ComponentCheck.cpp advapi32.lib
  4. Close the Command Prompt window.
  5. Using Windows Explorer, copy the executable file ComponentCheck.exe into {SamplesDir}\packages\Office2003PIA and {SamplesDir}\packages\Office2007PIA.

To prepare the primary interop assemblies bootstrapper package, follow these steps.

  1. Download Office 2003 Update: Redistributable Primary Interop Assemblies from the Microsoft Download Center.
  2. Run the primary interop assembly installer.
  3. Accept the Microsoft Software License Terms, which gives you the right to package the primary interop assemblies as part of your installer.
  4. In Windows Explorer, open the folder to which the installer extracted the files.
  5. Copy O2003PIA.msi into the directory {SamplesDir}\packages\Office2003PIA

For more details, go through these:

http://msdn.microsoft.com/en-us/library/bb332051(office.12).aspx

http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/cd733f1a-7db3-430d-9700-92dc7bdac077/?prof=required

Hope this helps!