How to deploy an Outlook 2010 Add-in Using C#.NET And Visual Studio 2010
In the previous blog, we walked through the steps to build an outlook 2010 add-in, how to create a custom task pane, add a custom context menu item and add a ribbon in the Outlook 2010. In this post, I’ll take you through the steps required to create a setup package so that you can distribute the add-in to others.
Creating a new Setup Project:
Returning to the Add-in project we created in this blog, we’ll now need to add a setup project. For that, we’ll use the MyFirstOutlookAddIn project.
Let’s create the setup project. Open Visual Studio 2010, go to file menu select Open-> Project/Solution and open the “MyFirstOutlookAddIn” project. Right click the MyFirstOutlookAddIn solution add new project. In the Installed templates expand to Other Project Types ->Setup and Deployment -> Visual Studio Installer and select “Setup Project” template. In the Name box, type MyFirstOutlookAddInSetup.
We should add the setup project with the existing MyFirstOutlookAddIn project solution to generate the “Primary Output” which we are going to create in this blog.
When the project has loaded in, Visual Studio will open File System window of our Setup Project. We can open the file system window by right clicking on MyFirstOutlookAddInSetup project, select View-> File System.
In the File System screen, right click on Application Folder select Properties Window.
In the Properties window, under DefaultLocation, change [ProgramFilesFolder][Manufacturer]\[ProductName] to [AppDataFolder][Manufacturer]\[ProductName]
Now, again right click Application Folder, select Add->Project Output and on the dialog that appears, choose “Primary Output”
We’ve now effectively told the setup project to install all our application goodness to the user’s AppData folder (Normally C:\Users\[username]\AppData in Windows 7, for example). We are doing this as this is a safe, sandboxed location that requires a minimum of privileges to install to. Here’s roughly how your screen should look now…
Now, we need to remove some of the .dll files that were added as Primary Output (because we do not need them). In Solution Explorer:
- Expand ‘Detected Dependencies’ in your Setup Project.
- Right click and ‘Exclude’ everything under this folder except for:
- Microsoft.NET Framework
There are now 2 files you need to reference explicitly in your setup project. These are files that are created when you build your solution – so you will need to point to the release folder. You may use debug if you wish – just remember you are pointing there. For production software, you should point to release. So, in the File System window of your setup project:
- Right-click the Application folder and select Add – File…
- Browse to your MyFirstOutlookAddIn folder, and then bin\Release
- Select the .dll.manifest, and .vsto files that reside there.
To complete the add-in setup package, it is required to add registry keys. When we run the add-in from visual studio, the keys will be added automatically in the background, but here we need to add it explicitly. The keys which we are adding will be saved to:
Open the Registry Panel in your Setup Project, then:
Expand the HKEY_CURRENT_USER key, then Software, and rename [Manufacturer] to Microsoft (because we are adding this key to the Microsoft Office section of the Registry).
Create a tree of key values underneath Microsoft by right click the Microsoft select New Key: Office\Outlook\Addins
Finally, create a key for your add-in. Give it a unique name (Ex.YourCompanyName.MyFirstOutlookAddIn), such that it is different from the add-in project name (so you can identify keys created by the installer, and keys created by Visual Studio).
In that key, set the following values:
String – “Description”
String – “FriendlyName”
String – “Manifest” – set this to “[TARGETDIR] MyFirstOutlookAddIn.vsto|vstolocal”
DWORD – “LoadBehavior” – set this to “3”
Select your new key (the one you just set values for) and in the Properties window, set DeleteAtUninstall to be true (important: do not set it for any keys higher up in the tree).
Now, we need to make sure that the Setup.exe you produce will check for prerequisites on the client system. This can be done by:
Right-click the MyFirstOutlookAddIn add-in project (not the setup project), select properties. In the properties screen select publish and click prerequisites button. A dialog window appears.
Ensure the following are ticked:
Microsoft .NET Framework 4 Client Profile (x86 and x64)
Microsoft Visual Studio 2010 Tools for Office Runtine (x86 and x64)
- Open the properties panel of your addin project and update the values there such as Version and Product Name.
- Open the User Interface editor of your setup project, and delete the Installation Folder screen. This will stop users from installing the add-in to a different location (that may stop your add-in from running).
Build your add-in, and then right-click your Setup Project and select Install. Otherwise you can go to the release folder of the setup project to get the installer.