Chris Hopkins' Blog - #makinitdostuff

The place where I post information about the products I manage; SharePoint, Yammer, Project and Visio and maybe from some that I don't!

VSTO 3.0 and Visio 2007 Essentials

VSTO 3.0 and Visio 2007 Essentials

  • Comments 2

Visual Studio Tools for Office 3.0 (VSTO) is the latest release of VSTO since the 2005 SE release. If you are a Visio add-in developer you probably already know that the 2005 SE release was the first version of VSTO that provided support for Visio add-ins. Before this your managed add-ins were either running unsecured or you had developed a shim to secure them.

In addition to the signed runtime that runs your add-in secure, the 2008 release now allows the Visio add-in developer to take advantage of the new Click-Once deployment features. Click-Once was introduced with .NET 2.0 Framework for Windows Forms applications and is now available for VSTO 3.0 based add-ins. With this functionality you can take advantage of the auto updating functionality to keep your users running the latest version of your add-in.

Additional articles on VSTO

What’s new in Visual Studio Tools for Office – An MSDN article with a detailed overview on the new features of this release. FYI a lot of new features in VSTO are not compatible with Visio add-in such as Document level customizations or Ribbon customizations.

VSTO Loader and Runtime Components – A blog by Andrew Whitechapel describing the different components of the VSTO runtime versions.

Architecture of Application-Level Add-Ins – An MSDN article describing the architecture of application level add-ins.

Setting up the VSTO project

Installing Visual Studio 2008 installs both the 2003 and 2007 add-in project templates including the runtime for VSTO 2005 SE and VSTO 3.0.

image

Creating a new project based on the Visio 2007 template will automatically configure the project specific to Visio add-in development by adding the following:

1. A reference to the Visio 2007 PIA will be added to the project along with other VSTO 3.0 runtime and Office related references.

image

2. A class named ‘ThisAddIn’ is generated containing the startup and shutdown handlers

image

The code for initializing your add-in should be placed in the Startup member and any code needed to cleanup and shutdown your add-in should be placed in the Shutdown member.

Adding code

At this point it is up to your imagination. I will tell you that the project already contains a nice typed reference to the host application, Globals.ThisAddIn.Application. You can use this anywhere in your add-in project when you need to get to the application object instance that loaded your add-in. If you are wondering where this is defined take a look at the ‘ThisAddIn.Designer.cs’ file in your project folder. This file was generated by the project template.

If you have not checked out the Visio 2007 SDK you should take a look. The Code Library that installs with the SDK contains a bunch of useful code that you can simply copy and paste to your project. It also contains a few developer tools such as the Event Viewer and the Solution Publisher.

Debugging

Another nice feature of the project template is the automatic configuration of the debug settings. After you create the project you can set a breakpoint in the Startup member and then press the play button. Your add-in will be registered in the registry, Visio will startup and the VSTO runtime will call into your assembly.

Deployment Scenarios

Up to this point you have an add-in that is running on your development machine and now you have to determine what deployment method you are going to use to make your add-in available to your users.

The majority of add-ins that I have seen or developed over the years typically fall into two categories that I like to call Tools and Solutions. I define a Tool as an add-in for Visio that is not dependent on a particular template or set of shapes. The Event Viewer that ships with the SDK is a classic example. I define a Solution as an add-in for Visio that is dependent on a particular template or set of shapes. The Space Plan solution that ships with Visio is a perfect example of this as its functionality is enabled when you are working with a drawing that was created from one of the floor plan templates.

So what does this have to do with deployment? It helps you determine the deployment method you are going to use. For the purposes of this article I am going to stick to the two basic options, Click-Once or Windows Installer (MSI).

Typically I find that Solution Publishing is largest deciding factor that determines if Click-Once or Windows Installer will be used. The Visio Solution Publishing tool (which ships with the Visio 2007 SDK) will add the necessary information to your MSI to “publish” your templates and stencils so that Visio will display them in the Getting Started pane, the File > New menu or File > Shapes menu.

image

I am not saying that templates and stencils cannot be deployed with Click-Once because they can, I am just pointing out that if you want your templates and stencils to be available to your users via the standard Visio methods then Click-Once is not the best choice. If your solution is designed to allow users access to solution specific templates and stencils via a custom menu or toolbar button then Click-Once might be a better choice.

Prerequisites

No matter which deployment method you choose the client machine will still need the following installed in order for a VSTO 3.0 based Visio add-in to function:

.NET 3.5 Framework

This package should already be setup and the option should already be selected in the Prerequisite dialog.

VSTO 3.0 Runtime

This package should already be setup and the option should already be selected in the Prerequisite dialog.

Office 2007 Interop files

You might have noticed that this option is not available in the Prerequisites dialog by default.

image

Take a look at Adding the Office Primary Interop Assemblies as a Prerequisite in your ClickOnce installer for instructions on how to add it.

Leave a Comment
  • Please add 6 and 5 and type the answer here:
  • Post
Page 1 of 1 (2 items)