Summary: Learn how to deploy a Microsoft Visual Studio Tools for the Office system 2010 add-in or document-
level solution using a Visual Studio 2010 setup project to create a Windows Installer package that targets the 2007
Microsoft Office system or Microsoft Office 2010.
Wouter van Vugt, Code Counsel
Ted Pattison, Ted Pattison Group
This article was updated by Microsoft with permission from the original authors.
Applies to: Visual Studio 2010 Tools for Office, 2007 Microsoft Office system,
Microsoft Office 2010, Visual Studio 2010.
Download: http://code.msdn.microsoft.com/VSTO2010MSI
Contents
You can develop a Visual Studio 2010 Tools for Office solution for the 2007 Microsoft Office system or Microsoft
Office 2010, and deploy the solution by using a Visual Studio 2010 Setup project to create a Windows Installer
package. The discussion includes steps for deploying a simple Office add-in.
For a discussion about how to deploy a solution built with Visual Studio Tools for Office 3.0, see
Deploying a Visual
Studio Tools for the Office System 3.0 Solution for the 2007 Microsoft Office System Using Windows Installer (Part
1 of 2) and
Deploying a Visual Studio Tools for the Office System 3.0 Solution for the 2007 Microsoft Office System
Using Windows Installer (Part 2 of 2).
You can use ClickOnce to create and install self-updating applications with minimal user interaction. This has an
automated mechanism for easily distributing updates to your application. However, ClickOnce is not capable of
deploying components that require administrative privilege such as machine level add-ins.
For solutions that require administrative privilege you can use Windows Installer to deploy a Visual Studio Tools for
Office customization. Windows Installer allows you to configure the deployment in great detail, but this does
require more effort to configure correctly. You lose the simple ease of deploying using ClickOnce technology and
advantages such as automated updates, but you receive benefits of configurability.
For an overview of how to deploy a Visual Studio Tools for the Office 2010 solution using ClickOnce, see
Deploying
Solutions for the 2007 Office System with ClickOnce Using Visual Studio 2008 Professional.
Both ClickOnce and Windows Installer packages need to perform the same rudimentary tasks when installing an
Office solution.
Required Prerequisite Components on the Target Computer
To run Visual Studio 2010 Tools for Office solutions, the following software must be available on the user computer.
Solution Specific Components
The installer package must install the following components to the user computer.
Registry Entries for Add-ins
Add-ins require a set of registry entries for the Microsoft Office application to locate the add-in. You should create
the registry entries as part of the deployment process. For more information about registry entries pertaining to a
Visual Studio Tools for Office add-in, see
Registry Entries for Application-Level Add-Ins. When developing an
Outlook add-in that displays custom form regions you should create additional registry keys as part of the
installation procedure to allow the form regions to be identified. For more information about registry entries
pertaining to Outlook form regions, see
Specifying Form Regions in the Windows Registry.
Document-level solutions do not require these registry entries because the customization is located by using
information inside the Microsoft Office document. For more information about the document properties used for
locating document-level customizations, see
Custom Document Properties Overview.
Trusting the Visual Studio Tools for Office Solution
Before you allow the customization to execute, a solution must be trusted. This trust relationship is based on the
signed application and deployment manifests. You can either sign the manifests with a certificate that identifies a
known and trusted publisher, or create a trust-relationship at installation time with an inclusion list entry or
installing to a trusted location. For more information about how to obtain a certificate for signing, see
ClickOnce
Deployment and Authenticode. For more information about using the user inclusion list, see
Trusting Office
Solutions by Using Inclusion Lists.
If neither option is used, a trust prompt is displayed to the users to let them decide whether to trust the solution.
You can add an inclusion list entry with a custom action in your Windows Installer file. For more information about
enabling the inclusion list, see
How to: Configure Inclusion List Security.
Document-level solutions have an extra requirement where the document location must also be trusted before the
Office application allows the customization to load. For more information about security related to document-level
solutions, see
Granting Trust to Documents.
The walkthroughs provided in this article use various sample files contained in the download. The download
contains the source code for all sample projects created in this article.
By default, these files are installed into the following folder:
%ProgramFiles%\Microsoft Visual Studio Tools for the Office system 2010
Resources\Windows Installer Sample\
This article refers to this installation folder as {SamplesDir}.
Download: http://code.msdn.microsoft.com/VSTO2010MSI
The Setup and Deployment project template in Visual Studio 2010 can be configured to create a Windows Installer
package that deploys a Visual Studio Tools for Office solution.
To create an installer for a Office solution, the following high level tasks must be accomplished.
Configure prerequisite components so that any missing pre-requisites can be installed on the end users
computers.Configure launch conditions to verify that the required prerequisite components are available. These
would be used to block the install in case all required pre-requisites are not installed. Start by creating the setup
project. This project contains the configuration for the Windows Installer package. Part of the configuration is
performed using built-in features. Additional tasks are performed using custom actions.
To create the AddInSetup project
.jpg)
Figure 1: Solution Explorer for the setup project
The setup project needs to deploy the ExcelAddIn DLL. You can configure the setup project for this task by adding
the ExcelAddIn project output to the setup project.
To add the ExcelAddIn project output
.jpg)
Figure 2: Dependencies for the setup project
The setup project needs to deploy the deployment manifest and application manifest. You can add these two files
to the setup project as stand-alone files from the output folder of the ExcelAddIn project.
To add the deployment and application manifests
.jpg)
Figure 3: Application and deployment manifests for the add-in
The downside of adding loose files to a setup project is that you reference the default output folder of the Release
build configuration explicitly. When you change the build configuration back to Debug, the setup project still
references the files from this folder. Because you should only distribute release builds, this is acceptable.
Alternatively, you can configure the Debug and Release build configuration to output their files to the same
directory.
Referencing the ExcelAddIn includes all the components that ExcelAddIn requires. These components must be
excluded and deployed using prerequisite packages to allow them to be registered correctly. Also, the Software
License Terms must be displayed and accepted before the installation begins.
To exclude the ExcelAddIn project dependencies
.jpg)
Figure 4: Excluding dependencies
You can configure your Windows Installer package to install the prerequisite components by adding a Setup
program, also known as a bootstrapper. The Setup program can include and install the redistributables provided by
the component vendors, a process called bootstrapping. For the ExcelAddIn, the following prerequisites must be
installed before the add-in can run correctly.
To configure dependent components as prerequisites
a. Select Create setup program to install prerequisite components. This creates the setup.exe
bootstrapper together with the MSI file.
b. In the Choose prerequisites to install list, select the appropriate packages depending on what
your solution targets.
c. For Specify the install location for prerequisites, select Download prerequisites from the
component vendor’s web site.
d. Click OK to close the Prerequisites dialog box.
e. Click OK to close the property pages of OfficeAddInSetup.
.jpg)
Figure 5: Prerequisites Dialog Box
| Note: |
| The configured prerequisite packages in your Visual Studio 2010 Setup Project are dependent on the selected build configuration. You must select the right prerequisite components for each build configuration that you use. The samples and procedures only use the default Release build configuration. |
Microsoft Office locates the application-level add-in by using registry keys specific to each Office Application. Keys
in the HKEY_CURRENT_USER hive will register the add-in for each individual user of the machine whereas keys
under the HKEY_LOCAL_MACHINE hive will register the add-in for all users of the machine.
For more information about registry keys, see Registry Entries for Application-Level Add-Ins.
To configure the registry
User/Machine
Hive\Software\Microsoft\Office\Excel\Addins\SampleCompany.ExcelAddIn
| Note: |
| The name of your company is used as a prefix for the name of the add-in. This provide uniqueness for this part of the registry key and allows add-ins with similar names originating from different suppliers to work without accidentally overwriting each other's registration keys. This does not provide full uniqueness but should suffice to prevent collisions. |
| 10. | Right-click the SampleCompany.ExcelAddIn key, select New and click String value. Use the text Description for the new value. | |
| 11. | Use this step to add three more values. Use the following names and data type. | |
| a. | FriendlyName of type String | |
| b. | LoadBehavior of type DWORD | |
| c. | Manifest of type String | |
| 12. | Right-click the Description value in the registry editor and click Properties Window. In the Properties Window enter Excel Demo AddIn for the Value property. | |
| 13. | Select the FriendlyName key in the registry editor. In the Properties Window, change the Value property to Excel Demo AddIn. | |
| 14. | Select the LoadBehavior key in the registry editor. In the Properties Window, change the Value property to 3. | |
| The value 3 for the LoadBehavior value indicates that the add-in should be loaded at startup of the host application. For more information about load behavior, see Registry Entries for Application-Level Add-Ins. | ||
| 15. | Select the Manifest key in the registry editor. In the Properties Window, change the Value property to [TARGETDIR]ExcelAddIn.vsto|vstolocal |
.jpg)
Figure 6: Setting up registry keys
| Note: |
| There are a few interesting notes on how the Visual Studio Tools for Office runtime locates the add-in. Visual Studio Tools for Office runtime searches for the deployment manifest indicated by the Manifest value. The [TARGETDIR] part is a macro that the Windows Installer expands to the actual folder where the add-in is installed. This macro expands to include the trailing \ character, so the filename of the deployment manifest is appended as ExcelAddIn.vsto without the \ character. Finally there is the use of the vstolocal postfix. This tells the Visual Studio Tools for Office runtime that the add-in should load from the location indicated by the Manifest value, and not loaded into the ClickOnce cache. Removing this postfix will cause the runtime to copy the customization into the ClickOnce cache. |
| Warning: |
| You should be very careful with the Registry Editor in Visual Studio. For example, if you accidentally set DeleteAtUninstall for the wrong key, you might delete an active part of the registry, leaving the user computer in an inconsistent, or even worse, broken state. |
Special considerations for Registering All User Add-ins for Office 2010 64-bit: Office 2010 64 bit looks for the add-
in registry keys under the 64-bit hive. In order to register add-ins under the native 64-bit registry hive, the setup
project’s target platform must be set to 64-bit only.
You cannot have a single MSI that will install for 32-bit as well as 64-bit Office versions. You must create two
separate MSI packages that target the 32-bit and 64-bit versions of Office separately.
.jpg)
Figure 7: Target Platform for registering add-ins with 64-bit Office 2010
When the user does not execute the setup bootstrapper (setup.exe), it is possible that the MSI package will install
on a computer without the required prerequisites. Launch conditions are used to prevent the ExcelAddIn
from installing on computers without installed prerequisites.
To see if the Visual Studio 2010 Tools for Office runtime is installed, check the following registry keys on the user
computer.
To configure launch conditions for Visual Studio 2010 Tools for Office Runtime
a. Set the value of (Name) to Search for VSTO 2010 Runtime.
b. Change the value of Property to VSTORuntimeRedist.
c. Set the value of RegKey to SOFTWARE\Microsoft\VSTO Runtime Setup\v4R
d. Leave the Root property set to vsdrrHKLM.
e. Change the Value property to Version.
.jpg)
Figure 8: Properties Window for the Search for Runtime Launch Condition
.jpg)
Figure 9: Properties Window for the Verify Runtime Availability launch condition
The Visual Studio 2010 Tools for Office runtime also ships with Microsoft Office 2010. However at the time of Office
2010 RTM, the runtime with Office only supports Office solutions that target the .NET Framework 3.5. If your
solution targets the .NET Framework 3.5, it can run either if Office 2010 is installed or if the Visual Studio 2010
Tools for Office Runtime redistributable is installed. If your Office solutions target the .NET Framework 4, you must
redistribute the Visual Studio 2010 Tools for Office runtime. The launch condition above explicitly checks for the
presence of the redistributable runtime. The following procedure demonstrates how you can modify the launch
condition so that it will also check for the presence for Microsoft Office 2010.
To configure launch conditions for Visual Studio 2010 Tools for Office Runtime
Select the Search for RegistryEntry1 search condition, right-click the condition and select Properties
Window.
In the Properties window, perform the following tasks.
a. Set the value of (Name) to Search for Office 2010 VSTO Runtime.
b. Change the value of Property to OfficeRuntime.
c. Set the value of RegKey to SOFTWARE\Microsoft\VSTO Runtime Setup\v4
d. Leave the Root property set to vsdrrHKLM.
e. Change the Value property to Version.
.png)
Figure 10: Properties Window for the Search for Runtime launch condition
In the Launch Conditions(OfficeAddInSetup) editor, select the Verify VSTO 2010 Runtime
availability launch condition defined earlier, right-click the condition and select Properties Window.
.jpg)
Figure 11: Properties Windows for the Verify Runtime Availability through Redist or Office 2010 launch condition
To configure launch conditions for Office 2010 Shared PIA
a. Set the value of the (Name) property to Search for Office 2010 Shared PIA
b. Set the value of the ComponentID property to {64E2917E-AA13-4CA4-BFFE-
EA6EDA3AFCB4}.
c. Set the value of the Property property to HASSHAREDPIA.
.jpg)
Figure 12: Properties Window for the Search for Office Shared PIA launch condition
In the Launch Conditions(ExcelAddInSetup) editor, right-click Condition1 and click Properties
Window to show the properties of the launch condition.
a. Set (Name) to Verify Office 2010 Shared PIA availability.
b. Set Condition to HASSHAREDPIA.
c. Leave InstallUrl blank.
d. Set Message to A required component for interacting with Excel is not available. Please
run setup.exe.
.jpg)
Figure 13: Properties Window for the Verify Office Shared PIA launch condition
You can further refine the launch conditions for the ExcelAddIn installation. For instance, it is useful to
verify if the actual target Office application is installed because each individual component can be
disabled by the user.
Component IDs of the Redistributable Primary Interop Assemblies for Microsoft Office 2010
| Primary interop assembly | Office 2010 component ID |
| Excel | {EA7564AC-C67D-4868-BE5C-26E4FC2223FF} |
| InfoPath | {4153F732-D670-4E44-8AB7-500F2B576BDA} |
| Outlook | {1D844339-3DAE-413E-BC13-62D6A52816B2} |
| PowerPoint | {EECBA6B8-3A62-44AD-99EB-8666265466F9} |
| Visio | {3EA123B5-6316-452E-9D51-A489E06E2347} |
| Word | {8B74A499-37F8-4DEA-B5A0-D72FC501CEFA} |
| Microsoft Forms 2.0 | {B2279272-3FD2-434D-B94E-E4E0F8561AC4} |
| Microsoft Graph | {011B9112-EBB1-4A6C-86CB-C2FDC9EA7B0E} |
| Smart Tag | {7102C98C-EF47-4F04-A227-FE33650BF954} |
| Office Shared | {64E2917E-AA13-4CA4-BFFE-EA6EDA3AFCB4} |
| Project | {957A4EC0-E67B-4E86-A383-6AF7270B216A} |
For information about the Microsoft Office 2007 component IDs, see
Deploying a Visual Studio Tools for the Office
System 3.0 Solution for the 2007 Microsoft Office System Using Windows Installer (Part 1 of 2).
The final set of launch conditions should resemble the following image.
.jpg)
Figure 14: Final launch conditions
The setup project is not compiled as part of a general solution compilation because the build can take a long time
on larger projects. You need to manually compile the setup project and copy the resulting files to an accessible
location.
To build the setup project
It is a good idea to test the basic setup before you add more advanced features to the setup project. You should
perform the following steps on a test computer where the add-in is not installed.
To test the ExcelAddIn setup
The Excel Office solution should install and run from the location specified during setup.
Additional Requirements for Document-level Solutions
Deploying document-level solutions require a few different configuration steps in the Windows Installer setup
project.
Document-level solutions do not make use of the registry. Instead, the location of the deployment manifest is
defined using custom document properties in the Microsoft Office file. By default, the location uses a relative path
to the deployment manifest, meaning that if the document is installed into the same folder as the customization
assembly you do not need to alter the manifest location contained within the document. However, if you intend to
deploy the document to a different folder as the customization assembly, you need to update the document
properties to a fully qualified path.
For more information about document properties used by Visual Studio Tools for Office, see
Custom Properties
Overview.
The following list outlines the basic steps required for a document-level solution.
Changing the Location of the Deployed Document
The download accompanying this article contains a sample custom action you use to move the document to the My
Documents folder and re-attach the customization. The custom action uses the ServerDocument class to re-
attach the customization.
The following steps assume you have created a similar setup project for a document-level solution called
ExcelWorkbookProject with a setup project called ExcelWorkbookSetup. The document-level solution sample
provided in the download accompanying this article is based on the Excel 2010 Workbook. The setup project has
been configured according to the steps outlined for creating an add-in installer, except for the registry keys that
are not used by document-level solutions.
To add the custom action project to your Visual Studio solution
.jpg)
Figure 15: Solution Explorer - AddCustomizationCustomAction
The custom action requires the solution ID of your Visual Studio Tools for Office document-level solution. This value
is retrieved from the Visual Studio project file. To begin, compile the document-level solution to add the solution ID
to this project file.
To retrieve the solution ID
.jpg)
Figure 16: Unloading Excel Document Solution
.jpg)
Figure 17: Retrieving the SolutionID
To configure the custom action with the solution ID
Visual Basic
<RunInstaller(True)> _
Public Class AddCustomization
Inherits Installer
Shared ReadOnly SolutionID As New Guid("2c49b8b0-1ddd-4fe2-8474-e4d80ed535ea")
End Class
C#
[RunInstaller(true)]
public class AddCustomization
: Installer
{
static readonly Guid SolutionID =
new Guid("2c49b8b0-1ddd-4fe2-8474-e4d80ed535ea");
}
| 6. | On the File menu, click Save AddCustomization.vb or SaveAddCustomization.cs to save your changes to the custom action class |
The last step is to configure the custom action for the Install and Uninstall steps of the Windows Installer
package. The Install step copies the document to the My Documents folder and re-attaches the customization. To
perform this task, you need to configure the custom action with additional data. The Uninstall step removes the
document from the My Documents folder. This task does not require additional configuration data.
To configure the setup project
.jpg)
Figure 18: Document Manifest Custom Action - Add Project Output Group
| 4. | In the Solution Explorer, right-click ExcelWorkbookSetup. |
| 5. | Expand View and click Custom Actions. |
| 6. | In the Custom Actions(ExcelWorkbookSetup) editor, right-click Custom Actions and click Add Custom Action. |
| 7. | In the Select Item in Project dialog box, in the Look In list, click Application Folder. Select Primary Output from AddCustomizationCustomAction(active) and click OK to add the custom action to the Install step. |
| 8. | Under the Installnode, right-click Primary output from AddCustomizationCustomAction(Active) and click Rename. Name the custom action Copy document to My Documents and attach customization. |
| 9. | Under the Uninstall node, right-click Primary output from AddCustomizationCustomAction(Active) and click Rename. Name the custom action Remove document from My Documents folder. |
.jpg)
Figure 19: Document Manifest Custom Actions
/assemblyLocation="[TARGETDIR]ExcelWorkbookProject.dll"/deploymentManifestLocation="[TARGETDIR]ExcelWorkbookProject.vsto"/documentLocation="[TARGETDIR]ExcelWorkbookProject.xlsx"
.jpg)
Figure 20: Custom Action to Copy Document to My Documents
Conclusion
This article provides an overview of deploying a Visual Studio Tools for Office solution using a Visual Studio 2010
Windows Installer package. This article provides a walkthrough to show how you can install the prerequisites (the
.NET Framework, the VSTO 2010 runtime), add the project output and manifests, create registry keys to load an
application-level add-in, and use a custom action to copy document-level solutions to the My Documents folder.
Additional Resources
Deploying Solutions for the 2007 Office System with ClickOnce Using Visual Studio 2008 Professional
How to: Install the Visual Studio Tools for Office Runtime
Office Primary Interop Assemblies
Registry Entries for Application-Level Add-Ins
Custom Document Properties Overview
Specifying Form Regions in the Windows Registry
About the Authors
Wouter van Vugt is a Microsoft MVP with Office Open XML technologies and an independent consultant focusing on
creating Office Business Applications (OBAs) with SharePoint, Microsoft Office, and related .NET technologies.
Wouter is a frequent contributor to developer community sites such as
OpenXmlDeveloper.org and
MSDN. He has
published several white papers and articles as well a book available on line titled Open XML: Explained e-book.
Wouter is the founder of Code-Counsel, a Dutch company focusing on delivering cutting-edge technical content
through a variety of channels. You can find out more about Wouter by reading his blog and visiting the
Code-
Counsel Web site.
Ted Pattison is a SharePoint MVP, author, trainer and the founder of Ted Pattison Group. In the fall of 2005, Ted
was hired by Microsoft’s Developer Platform Evangelism group to author the Ascend developer training curriculum
for Windows SharePoint Services 3.0 and Microsoft Office SharePoint Server 2007. Since that time, Ted has been
entirely focused on educating professional developers on SharePoint 2007 technologies. Ted has just finished
writing a book for Microsoft Press titled Inside Windows SharePoint Services 3.0 that focuses on how to use
SharePoint as a development platform for building business solutions. Ted also writes a developer-focused column
for MSDN Magazine titled Office Space.