VSTO and Visual Studio Standard Edition ... Solution

10 March 2009

In a previous post, I described how annoying it was that Microsoft wanted to keep me from improving their OneNote application, even though I have a legal copy of both it and Visual Studio 2008. I should have mentioned that I understand completely if they want to put the Visual Studio Tools for Office (VSTO) into the Professional Edition and not the Standard Edition. That's their right, even if I think it's stupid. But I was surprised that they would keep people from using the API (which, after all, is just part of a set of DLLs), even if we hadn't purchased the specialized tools. .NET applications, for example, can be written, compiled & run without purchasing any version of Visual Studio. Well, it turns out you can write applications that use the new API without having VSTO; it just takes a little more effort.

Generally, in the .NET world, if you want to use someone's API, you just reference their DLL. In Visual Studio, this is pretty straight-forward: Right-click on the References folder, choose "Add Reference..." and either find it in the list of .NET references or browse for the standalone DLL. In fact, that's exactly what this very useful PDF document about creating a OneNote plug-in and this two-part introduction to using the OneNote API suggest. Unfortunately, neither the .NET reference nor the COM reference appeared among my choices. So I went hunting for the DLLs.

This is where I ran into trouble. The Microsoft Office 2007 API DLLs are officially called "Primary Interop Assemblies" (PIA) because they facilitate the inter-operation between your application and the vendor's application (in this case, the Microsoft Office applications). When you install Office 2007, these assemblies (Microsoft.Office.Interop.OneNote.dll and the like) are installed in the Global Assembly Cache (GAC), but can't be found in Vista. Nor could I find them on the Web. VSTO, I'm told, installs some copies for you to use during development, but that didn't help me since I didn't have VSTO.

After much searching (and cursing), I finally realized that I didn't actually need the DLLs. The APIs are in the GAC, so if I could get my project to reference those, I'd be fine. So I downloaded an open-source project for OneNote (the OneNote DevPal) and opened its project file (.csproj) in notepad. I copied the ItemGroup information pertaining to the OneNote reference out of that file and into my own .csproj file by hand. Then, when I re-opened my own little test add-in, everything was hunky dory.

The XML that I copied looked something like this:

<itemgroup>
<reference include="Office, Version=12.0.0.0">
<private>False</private>
</reference>
<reference include="Microsoft.Office.Interop.OneNote, Version=12.0.0.0">
<private>False</private>
</reference>
<reference include="stdole">
<private>False</private>
</reference>
</itemgroup>

With that little bit of hackery, I was finally able to construct my own test add-in based on Dan Escapa's guide. If you're interested in creating OneNote add-ins, I suggest you start there as well. Keep in mind some errata, however:

* When it says "YOUR GUID", it means a new GUID created specifically for the add-in. Don't use the project GUID, or anything else generated by VS2008. (VS2008 can create GUIDs for you, btw; just look under the Tools menu.)

* You'll have to run Visual Studio 2008 as an administrator (right-click the shortcut, choose "Run as Administrator") if you're in Vista. I think that's due to the modification of the registry that the Setup project performs.

Have fun!

0 comments: