Pieter van der Westhuizen

Version-neutrality for your Office extensions: Add-in Express vs. VSTO

I have to be honest. I have become very spoiled with Add-in Express when it comes to Microsoft Office development, a fact that I once again realized after a discussion with the gang about Visual Studio Tools for Office (VSTO) and Add-in Express.

I think that one of the biggest features I took for granted with Add-in Express, is just how easy it is to create true version neutral Microsoft Office add-ins.

Creating a version-neutral add-in for Office 2013-2000 using Add-in Express

In essence to create a version neutral Office add-in using Add-in Express takes a minimum of four mouse clicks. When starting a new ADX COM Add-in project in Visual Studio, the new COM Add-in Wizard will prompt you to select the minimum supported Office version you want your add-in to run in. Add-in Express works with Visual Studio 2012, VS 2010 and lower.

The first click would be selecting the Microsoft Office version and the second the Next button.

Selecting the minumum supported Microsoft Office version

The third click would be selecting the Microsoft Office application you need your add-in to support and the last and fourth click would once again be the Next button (I’m not counting the number of checkboxes clicked on).

Selecting the Microsoft Office applications to be supported by your add-in

That’s it. In just 4 simple clicks you have a version neutral Microsoft Office Add-in, that will run in Office versions of 2000 to 2013 for Excel, Word and Outlook. Not only that, but it will also automatically work with both 32 and 64-bit versions of Office 2010.

The new COM Add-in wizard will also automatically include and reference the correct Office Interop assemblies for the Office version you’ve selected. What does this mean? Well, if you’ve selected Microsoft Office 2000 as the minimum supported version, you would only be able to code against objects in that version of Office, which in turn means your code will work for all Office versions 2000 and up. By referencing the “lowest” version of Office’s Interop assemblies Add-in Express disciplines or rather gives you a gentle nudge in the right direction, to write true version neutral code.

Add-in Express is not just version neutral for Microsoft Office but for Visual Studio as well. You can create Office 2000, XP, 2003, 2007 and 2010 (32 and 64-bit) add-in with Visual Studio 2005, 2008, 2010, including the Express Editions as well as with the latest Visual Studio 2012!

All done with four clicks people, four! Count them.

Creating an Office add-in using Visual Studio tools for Office

Let’s assume I have Visual Studio 2010 installed and want to create an Office add-in that will work for Microsoft Office 2000 and up, the first hurdle is that Visual Studio 2010 (VSTO 2010) only supports solutions for Office 2007 and 2010. In order to create add-ins for Office 2003 I’ll need to install either Visual Studio 2003 with VSTO 2005 or Visual Studio 2008 with VSTO 2005 SE/VSTO 2008.

Ok, so not too big of a deal if you still have Visual Studio 2008 installed. But still, how would you create an add-in that will support Office 2000?

One way is to use the Shared Add-in project template available in any version of Visual Studio.

Creating a shared add-in in Vusual Studio

This project template will ask you which Office applications you would like your add-in to load in, so at least that’s taken care of for you, however, you still need to manually include any Primary Interop Assemblies (PIA) for the specific versions of Office you would like to support. I also need to mention that it creates strange code where you manually have to determine the host application.

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode,
	object addInInst, ref System.Array custom)
{
	applicationObject = application;
	addInInstance = addInInst;
}

Since we want to support Office 2000 and up we could just include the PIAs for Office 2000, right? Well, no we can’t. You see there are no PIAs for Office 2000, you could always use the Office XP or Office 2003 PIA. However, here is what Microsoft had to say about this idea:

“Microsoft does not guarantee that the Office PIAs will be backwardly compatible or that the various versions of the Office PIAs can be run side-by-side in the same instance of an Office application. Office XP managed code add-ins must be built against the Office XP PIAs. The Office 2003 managed code add-ins must be built against the Office 2003 PIAs. The Office 2007 managed code add-ins must be built against the Office 2007 PIAs. Therefore, if you build an add-in solution that you intend to use with several versions of Office, Microsoft recommends that you build a version of your add-in for each version of Office that you intend to support.”

Source: Information about designing Office add-ins by using the .NET Framework.

Is it just me or does this remind you of 15th century maps?

Here be dragons

It’s a case of venture there at your own risk. It might work, then again it might not. A work around for this is to create individual versions of your add-in for each Microsoft Office version you want to support.

Not sure about you but at this stage, I’ve given up my plans of developing a version of my add-in that will support all versions of Office and just create one add-in that will support the latest version of Office…

How does Add-in Express solve the version-neutrality problem?

Version neutrality is not a trivial task when it comes to Office add-ins, and we’ll explore it more in the coming post, but I want to wrap up this article by mentioning that Add-in Express solves the version neutrality problem for Office 2000 and up by including version independent interop assemblies when you create a new COM Add-in project. These are assemblies created by Add-in Express and they will allow you to create COM add-in for all Office version from 2000 right up to Office 2013.

I don’t know about you, but when I want to create an Office Add-in I want to get down to business and do it. I certainly do not want to battle with sorting out PIAs and hope that my add-in might or might not work as intended in multiple versions of Office.

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

Last updated: 6-Feb-2013.

Add-in Express vs. VSTO:

You may also be interested in:

Post a comment

Have any questions? Ask us right now!