Thursday, January 28, 2010

Developing Office 2003 Add-ins with Visual Studio 2008

I want to summarize some lessons I had to learn “the hard way”.  Hopefully, it will be of benefit to someone else who has to go down this path.

Creating an Office Add-in in Visual Studio 2008 can be very easy.  Microsoft has done a good job of making that easy to do.  Deploying the Add-in; however, is a different story…that’s where it gets a lot more complicated.

First, you need to be aware of everything in my previous post on this topic:

Developing VSTO Applications

There’s another “gotcha” that I recently discovered that you also need to be aware of and it deals with the VSTO runtime.  There are two versions of the VSTO runtime in use:

  • VSTO SE Runtime was introduced with Visual Studio 2005
  • VSTO 3.0 Runtime was introduced with Visual Studio 2008

The natural conclusion that someone would draw is that the VSTO 3.0 Runtime superseded the VSTO SE Runtime because the VSTO SE Runtime isn’t even offered as a choice for a prerequisite in Visual Studio 2008 – that assumption, unfortunately, is wrong.  That’s the lesson I had to learn “the hard way”.

If you’re developing an Office Add-in in Visual Studio 2008 that is targeted for Office 2003 and you develop it using the VSTO 3.0 Runtime, it won’t work.   It will work in the development environment; however, when you deploy it to a target machine, it will fail to load.  In Visio 2003, if you examine the COM Add-ins, you will see the Add-in is present in the list of Add-in’s and it is unchecked with a message that if failed to load due to a run-time error.  This error can be very difficult to track down because there is nothing that gives you much of a clue of exactly what is causing the error.

The problem as I discovered is that the VSTO 3.0 Runtime doesn’t supersede the VSTO SE runtime as I thought for Office 2003 applications.  If you’re targeting Office 2003 applications, you still need to use the VSTO SE runtime or your Add-in will not load with the symptoms I described.  The VSTO 3.0 runtime works only with Office 2007 Add-ins.

Visual Studio 2008 certainly doesn’t make it easy to discover this because it doesn’t even offer the choice of adding the VSTO SE runtime as a prerequisite.  When you create an Office 2003 Add-in with VS2008, it creates the Add-in for you including the Setup project and you think you’re done just by adding the VSTO 3.0 runtime as a prerequisite…that’s where developers will get tripped up.  You have to add the VSTO SE runtime as a prerequisite to the Setup project instead of the VSTO 3.0 runtime and in order to do that, you need to add it as a custom prerequisite to VS2008 because it isn’t even in the list of standard prerequisites offered in VS2008. 

Here are some instructions for doing that:

  1. Download the VSTO SE Deployment Sample from the following location:

    VSTO SE Deployment Sample

  2. Install it on your development system

  3. Copy the entire contents of the package to the VS2008 Packages location on your development system:

    The files will normally be installed in the following directory:

    C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample Version 3\packages\VSTOSERuntime

    In order to get the VSTO SE runtime to show up as a prerequisite in VS2008, copy the files to VSTOSE Runtime files to the following location:

    C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages

  4. Download the VSTO SE runtime redistributable from the following location:

    VSTO SE Runtime Redistributable

  5. Copy the VSTOR.exe file from the download location to the VS2008 package location in step 3

I hope this helps someone avoid chasing around all over the web to find this information.  What makes this especially confusing is that many of the articles you will find on the web on this subject are written around VS2005 and haven’t been updated for VS2008.  You will need to ignore many of the things in these articles that are specific to VS2005 (For example, most articles talk about using the .Net Framework 2.0 as a prerequisite – that isn’t necessary - .Net Framework 3.5 works fine).

My thanks to Bessie Zhao from Microsoft for helping me unravel this puzzle.

Chuck

0 comments:

Post a Comment