If you want to create a Visio add-in, there are several options available. You can go with plain COM addin, VSTO (Visual Studio Tools for Office) addin, or with a VSL. This project template provides an improved starting point to build managed Visio addins with Visual studio (including free Visual Studio Community Edition).
What the addin project provides to help you get started
– The basic addin project, based on VSTO or COM.
Installer project, which is fully customizable (based on WIX) where you can select to install additional Visio files such as stencils or templates. Or additional DLLs. Or PDFs. Or whatever. The installer can publish your stencils and templates to Visio, so that they are available as built-in templates. You just specify the files, the wizard takes care of the rest. If you want to customize names/folders/versions you can still do so afterwards by modifying it in the generated project.
User Interface to start with (ribbon xml/command bars)
A TaskPane framework (not really a "TaskPane" in case of Visio , but something like it – a docking panel), and a toggle button to control it
Custom images support code for the buttons. You can change them, or design your own based on the example.
State support (enabled/visible) for the buttons
Optional support for legacy Visio support (2003/2007) with command bar buttons
Sample result in Visio of what you get (checkboxes in the wizard set to allow "panel" and "ribbon" features):
Source code of the extension is availble at the github (you may be interested in that if you build Visual Studio project templates, or build WIX extensions. The project includes a full-blown extension, that includes compiler with custom tables, binder extension, and also decompiler extnesion): https://github.com/nbelyh/VisioPanelAddinVSTO
- In Visual Studio, go to:
Tools -> Extensions and updates -> Online -> Search for the project -> Install
- Use New project -> Select the project type (under C# tab, or C++ tab)
3. The project wizard opens. See options below.
Create Visio Addin
You must check this if you want to create a Visio addin project. Note that if you deselect this option, then you still will be able to proceed. This may be what you want in case you want to create an installer to install (publish) just some Visio files (such as stencils or templates). The wizard will let you select those on the next steps.
Specify the name of the Add-in to be shown in Visio User Interface.
The name of the publisher to show in install/uninstall. Note that to show publisher name in Visio, you need a certificate to sign the addin (this "manufacturer" field will not work for this purpose)
The description of the addin to be shown in Visio User Interface.
The type of the addin to create. In most cases, the VSTO addin is recommended. If you are in doubt, just select it. You may want COM (in Visual Studio that’s called "Shared Addin") if you migrate your old code, or if you want to support something like Visio 2013.
Create setup project
Check if you want a WIX installer project to install your addin. The addin setup project provides you with some neat features which are not available otherwise. But anyways, you for VSTO addin you can use ClickOnce publishing instead (available via Visual Studio addin project settings)
Include Visio Stencils and Templates
The visio files to be deployed along with the addin. These files are published (this option works identical to Visio solution publishing). By default, the stencils/templates are published for all Visio versions, for all languages. You can fine-tune your stensil/templates afterwards by changing attributes of the corresponding <Publish> element. You can also add stencils/templates afterwards, i.e. this is a convenience feature.
Copy files to project directory
If checked, the selected files will be copied to the project directory, and these (copied) files will be included in the setup. If you uncheck this flag, then original source files will be picked up by setup, but please mind the file paths then (you may end up with absolute paths – modify them in the generated project as needed)
Provide user interface for the installer
If checked (default), the installer will include some (selected) user interface. If you uncheck this, the installer will not include any UI. For the details on UI, please refer to wix UI interface options.
User interface language
You can specify the language of the installer (should be one of the supported languages). Note that if your installer includes files with non-english symbuls, you should select the language where these symbols are valid. Like, select "ru-RU" if you have files with cyrilic symbols.
- Build an run
For VSTO project type, just hit F5, the debugging should start automatically.
For COM project type, first build the solution and install the project. To ease debugging, the default project has "Register for COM interop" option set in debug configuration (this will register the addin automatically at project location instead of installed location after you build it). Note that you’ll need to start Visual Studio as Administrator for this to work. Also note that by default latest Visio is selected for debugging (if you have more than one Visio versions installed). You can change that in the project settings.
The start-up project consists of a few classes. Some of them are generated or note depending on the checkboxes set on project creation.
ThisAddin – (always generated) is supposed to contains startup functionality of the addin, and the code.
AddinRibbon – generated if ribbon support was selected; defines infrastructure needed to support the ribbon.
AddinCommandBars – generated to support Command Bars UI (for old versions of Visio), if selected.
PanelFrame, PanelManager – (if you have selected to include task pane) – helper classes to support task pane integration.
TheForm – The form to be shown in the task pane. This is the class to define your user interface for the task pane.
Adding new commands
If you have selected to use ribbon designer, just add a button to the ribbon using the designer. To create handler, double click it.. Simple as that.
To add a new command/edit existing command with XML
Ribbon interface: Edit the Ribbon.xml file and add buttons/controls. Note many callback functions for the buttons/controls are already defined in the AddinRibbon file. These include:
To add a button, you can just add it in the Ribbon.xml like this:
You can just modify the Addin.cs file OnCommand/IsCommandEnabled/IsCommandChecked to process the command. Note that there is no need to define all handlers; you can keep only the ones you need (if you don’t need dynamic images or dynamic text, don’t add OnGetRibbonLabel/GetRibbonImage). The processing is done in the Addin.cs to have common place for ribbon/command bars, to support also old versions of Visio.
Command bars interface: Add the new command ids (string) it to initialization list of StartupCommandBars() function. Process them in the Addin.cs OnCommand/GetRibbonImage/etc.
You can configure templates/stencils after adding them, to specify names/locations where they should be made available in Visio user interface. You have autocomplete in the project to help you with this. For example, to publish the same stencil under different names depending on Visio language, you can do (note that this is artificial example, normally you should create 3 stencils, and publish them with corresponding languages). Also this will move first 2 shapes as "Quick Shapes".
Adding other files to the setup (like related DLLs)
This example address the case when you in addition to the addin dll, have other dll project you want to include in the (WIX) setup. The best way to do this is to use project reference.
Basically, you need to add a reference to the dll project to the wix (setup) project:
and the add the output of the project to be installed in the wxs file, like this: