Eugene Starostin

Microsoft Office PIAs (Primary Interop Assemblies) and Add-in Express .NET

Starting from version 2.3 Add-in Express integrates Microsoft Office PIAs into add-in solutions. Here I will try to set forth my point of view on using the Office Primary Interop Assemblies in our projects.

Well, I’d like to note that Add-in Express for Office and .net is quite tolerant with this issue. You remember that all add-in solutions are generated by a special wizard, don’t you? And the first thing you will be prompted to do is to select the programming language for the project:

Following the dialog window above Add-in Express will gently ask you to select Microsoft Office PIAs that you are planning to use. Here is this dialog window:

What will Add-in Express do if you select one or more applications? It will include in the project PIAs for the selected applications and will add to the add-in module property-wrappers over the HostApplication property. For example, for Outlook this property will look like this:

Public ReadOnly Property OutlookApp() As Outlook._Application
  Get
    Return HostApplication
  End Get
End Property

These properties just type cast the HostApplication property for your convenience. And instead of casting the HostApplication property to Microsoft.Office.Interop.Outlook._Application every time, you will be able to call OutlookApp.

The work would seem to be completed, and you can freely use the connected PIAs and generated property-wrappers. But there are some crucial moments here:

  • Add-in Express allows using the PIAs that are installed on your PC. So, if you have the MS Office 2007 PIAs installed, it is these Primary Interop Assemblies that will be added to your COM add-in project. It means your add-in will not work correctly under Office 2000, 2002 and 2003.
  • Add-in Express provides version-neutral interop assemblies generated for the earliest version of every Office application. When using these interops, you are guaranteed that your COM add-in will support all versions of any given Office application. That is, you can have any Office version installed on your PC! For instance, you can have Excel, Outlook, Word, or PowerPoint from Office 2007 installed and nevertheless you can develop your add-in for Excel, Outlook, Word etc from the Office 2000 suite. Isn’t that nice?
  • The PIAs or version-independent interops are automatically copied to one of your project subfolders and are automatically signed with a strong name. Naturally, it happens only in case you check the corresponding flags in that dialog window.

Now, let me draw your attention to the following points:

  • If you want to create the COM add-in working correctly under applications starting from version 2000 to Office 2007, you can use interop assemblies provided by Add-in Express and develop your add-in on a PC with any Office version installed.
  • If you want to get the add-in working under versions 2003 and 2007 only, install Office 2003 on your PC and use Office 2003 PIAs in your add-in.
  • If you want to build the add-in for version 2000 and higher, but have Office 2007 only, use the Office 2000 interops from Add-in Express. I just note that we do not give any guarantee on these interop assemblies. Neither do Microsoft :-)
  • To access properties and methods from a newer Office version, you use late binding. It is not so difficult as it may seem. And it will work under Outlook 2000 and under Outlook 2007. I’ve checked :-)

That’s all. At last, I renamed the Microsoft Visual Studio 2005 shortcut to Microsoft Very Slow 2005. My laptop (Acer 662LCi) cannot cope with this monstrous IDE.

Last updated on 13-May-2008.

Related posts:

A bit about Microsoft Office PIA – for Office 2000, 2002, 2003 and Office 2007

Post a comment

Have any questions? Ask us right now!