Outlook 2013 add-ins and Visual Studio 2012: Getting started for VSTO developers
In my last article we took a whirlwind trip through the process of starting a new Add-in Express Office add-in from a VSTO developer’s point of view.
Today we’ll focus on how developers, coming from a Visual Studio Tools for Office (VSTO) background, can get started developing add-ins for Outlook 2013 using Add-in Express for Office amd .NET and Visual Studio 2012 (C#, VB.NET or C++.NET).
- Accessing Outlook application objects and events
- UI designers – Outlook ribbons, command bars and context menus
- Deployment Options – ClickOnce, msi and ClickTwice
Accessing Outlook application objects and events
When you create a new VSTO Outlook addin project, you can access the Outlook application object by using the Application object as illustrated below.
private void ThisAddIn_Startup(object sender, System.EventArgs e) { string version = this.Application.Version; }
From there you can access a host of properties and methods that are available on the Outlook Application object. Add-in Express works in a similar fashion by creating a property that contains a reference to the Outlook Application object for you. When you create a new Add-in Express project, you’ll see the following in the AddinModule class:
public Outlook._Application OutlookApp { get { return (HostApplication as Outlook._Application); } }
To accomplish hooking up to the events of the Outlook application in VSTO, requires a bit of code. In the following example we’ve added the following code to respond to the NewInspector event:
Outlook.Inspectors inspectors = null; private void ThisAddIn_Startup(object sender, System.EventArgs e) { inspectors = this.Application.Inspectors; inspectors.NewInspector += inspectors_NewInspector; }
Add-in Express makes it very easy to discover and respond to the various Outlook events. First, all you need to do is add a new Microsoft Outlook Events component to the AddinModule designer surface.
When you select the Outlook events component and view its event list, you’ll see all Outlook events. You only need to double-click next to its name in the Visual Studio properties window to generate an event handler for a specific event.
This will then generate a new event handler inside the AddinModule class for you:
private void adxOutlookEvents_NewInspector(object sender, object inspector, string folderName) { Console.WriteLine("NewInspector event called!"); }
UI designers – Outlook ribbons, command bars and context menus
When it comes to designing the UI for your Outlook add-ins, nothing beats Add-in Express! With Add-in Express you get a vast array of visual designers for all Office controls. For example, if you want to add a custom ribbon tab, you only need to click on its button on the AddinModule designer.
Creating a custom Outlook ribbon
Once the Ribbon Tab component is added to the designer surface you can use the built-in visual designer to create the UI of the ribbon tab. The visual designer makes it incredibly easy to create ribbon tabs of varying complexity. VSTO only has one visual designer, and this is used for designing Ribbon tabs, but when you need to create a complex ribbon you need to use the XML designer. With Add-in Express you can design a very complex Ribbon as well as a number of other components like the backstage view and solutions module, without the use of XML!
The ribbon tab is context-sensitive, which means you can set its properties for when it should be displayed. This can be done by using the Ribbons property, for example, when you set the Ribbons property to OutlookContact; OutlookMailRead as illustrated below, the ribbon tab will show when the user opens an Outlook Contact and reads an e-mail:
Creating a custom Outlook toolbar
If you need to support a version of Outlook that pre-dates the ribbon UI, no problem. As I’ve mentioned in my previous article, Add-in Express supports true version independence, so all you need to do is to add a Command Bar to Outlook 2007 or Outlook 2003 is add a Command Bar component to the same AddinModule designer surface. That’s right, you can add everything to the same add-in.
As with the Ribbon tab, you can also design you command bar with the visual designer right inside Visual Studio.
Building a custom Outlook context menu
Context menus are another menu component that Outlook developers need to customize on a regular basis. Add-in Express provides a Context menu component that also provides a visual designer for any context menu.
You can then choose in which Office application your context-menu should be used by setting the SupportedApp property. When you set this property’s value to Outlook, the CommandBarName property will display all the available context menu names available in Outlook.
Inspector and Explorer regions
With VSTO when you want to add a region to an Outlook form you would add a new Outlook Form region item to your project and work through the “New Outlook Form Region” wizard to set up your new region.
When creating a new form (Inspector) or Explorer region with Add-in Express, you also need to first add a new ADX Outlook Form item to your project.
This item is similar to a standard Windows form and you can design its layout as you would any other windows form or control.
Before you can use this form though, you need to add an ADX Forms Manager component to the AddinModule designer.
This component is used to specify which ADX Outlook form control should be used in which Outlook Explorer or Inspector region. Add-in Express provides a long list of different layout options. In order to specify an Explorer region, you need to set the ExplorerLayout property and for an Inspector region you’ll use the InspectorLayout property. Form regions can also be context-sensitive as you can specify the Outlook item types the region should display by using the InspectorItemTypes and ExplorerItemTypes properties.
Additional modules
Because Add-in Express provides visual designers, the AddinModule designer surface can get somewhat cluttered with a lot of components for large add-ins. If this occurs you can simply add an Additional Module item to your project, which will give you another designer surface to add components to.
Additional modules also allow you to enable or disable certain aspects of your add-in. For example if you have different editions of your Outlook plugin you do not need to build a separate project for each. You only need to enable or disable the modules by setting its Enabled property in the main module’s Modules property.
Deployment Options – ClickOnce, msi and ClickTwice
When you’ve finished your VSTO Outlook add-in and would like to deploy it to users, you would generally either build a Visual Studio installer project or a ClickOnce installer. But since Visual Studio 2012, you no longer have the option to build VS installer project, so the quickest way to publish would be ClickOnce.
Add-in Express gives you three options for packaging and distributing your Add-in. The first would be a MSI-based installer.
MSI base installer
To create an installer for your project, simply right-click on your project in the Visual Studio Solution Explorer window and select “Create Setup Project” from the context-menu.
If you have InstallShield or the WiX Toolset installed, Add-in Express will automatically build a MSI based setup project for you, which you can distribute to your users as you would any standard setup program.
ClickTwice
ClickTwice allows users to run MSI setup programs from either their intranet or the internet. Think of ClickTwice as a combination of ClickOnce and MSI. To build a ClickTwice installer for your add-in, select “Publish ADX Project” from the Visual Studio Project menu.
You’ll need to first create a standard setup (MSI) program as you need to specify the MSI file in the Publish form.
ClickOnce
ClickOnce will be familiar to most VSTO developers and Add-in Express creates click once installers in a similar way to VSTO. When you want to publish your add-in you’ll need to first click the Populate button and specify a certificate file.
All you need to do is provide your user with the url to the installer and they can install your add-in via the internet or your local intranet.
As you can see Add-in Express makes the job of creating, designing and publishing your Outlook add-in much easier than having to do it with VSTO. Add-in Express is built to help you focus on getting the job done rather than having to focus on the plumbing.
Thank you for reading. Until next time, keep coding!
Office 2013 add-ins and VS 2012: Getting started for VSTO developers
- Part 1: Office 2013 add-ins and VS 2012: getting started for VSTO developers
- Part 3: Develop Excel 2013 plugins in Visual Studio 2012
3 Comments
Hi Pieter,
I have one question,
is it possible for me to include the following dll package https://www.microsoft.com/en-us/download/details.aspx?id=21786
in the MSI base installer?
Thanks for your help
I use the WiX installer,
thanks
Hi Anderson,
Yes, You can include any additional files you want to deploy to the client machine in the setup.