Export (0) Print
Expand All
Expand Minimize

Deploying an Office 2007 .NET 3.5 Project and an Office 2010 NET 4.0 Project

Office 2010

Office Visual How To

Summary:  Using Visual Studio 2010, you can build solutions for the Microsoft Office 2007 system and Microsoft Office 2010 that target both the .NET Framework 3.5 and the .NET Framework 4. The requirements for installing these solutions vary depending on the version of Office and the .NET Framework that your solution targets.

Last modified: September 12, 2012

Applies to: Excel 2010 | Office 2007 | Office 2010 | Open XML | PowerPoint 2010 | VBA | Visual Studio | Word 2010

Published:  August 2010

Provided by:  Robert Green, MVP, MCW Technologies, LLC

Overview

With Microsoft Visual Studio 2010, you can create document-level customizations and application-level add-ins for both the Microsoft Office 2007 system and Microsoft Office 2010. In both cases, you can target the Microsoft .NET Framework 3.5 or .NET Framework 4. After you test the solutions on your computer, you can deploy them to end-users. Regardless of the version of Office you use and the version of the .NET Framework you target, you must make sure users have required software on their computers.

Users must have Office installed in addition to the appropriate version of the .NET Framework. In addition, they need the Visual Studio 2010 Tools for Office Runtime. If they use the Microsoft Office 2007 system, then the Office 2007 Primary Interop Assemblies are required. If they use Office 2010, then the Office extensions for the .NET Framework 3.5 or 4 are required.

Code It

Follow these steps to review Microsoft Office 2007 system and Office 2010 solutions that target the .NET Framework 3.5 and the .NET Framework 4.

Reviewing the Solutions

This article walks you through four versions of the SmartTagAddIn project. This is a Word application-level add-in that provides a custom smart tag which recognizes temperatures in Fahrenheit or Celsius, and offers the option to convert to the other scale, shown in Figure 1 and Figure 2. The Ribbon customization, shown in Figure 3 and Figure 4, enables users to enter a temperature value, set its scale, and then insert the temperature into the workbook. You may find the internal code for the add-in to be of interest, but it's not the focus of this article. Instead, this article focuses on how to deploy Office solutions.

Figure 1. The Word 2007 smart tag helps convert temperatures from one scale to another

Word 2007 smart tag to convert temperatures

Figure 2. The Word 2010 smart tag helps convert temperatures from one scale to another

Word 2010 smart tag to convert temperatures

Figure 3. The Word 2007 Ribbon customization enables users to insert a formatted temperature value

Word 2007 ribbon customization

Figure 4. The Word 2010 Ribbon customization enables users to insert a formatted temperature value

Word 2010 ribbon customization

Version 1: Office 2007 Solutions That Target the .NET Framework 3.5

  1. In Visual Studio 2010, load the sample project, SmartTagAddIn_Office2007_NET35.sln.

  2. If you are using Visual Basic, click the Show All button in the Solution Explorer.

  3. Expand the References node in the Solution Explorer.

    Microsoft.Office.Interop.SmartTag and Microsoft.Office.Interop.Word are primary interop assemblies (PIAs). The PIAs enable managed code to interact with a Microsoft Office application's COM-based object model. These PIAs must be present on the end user's computer to run a solution that targets the .NET Framework 3.5.

  4. On the Project menu, select the SmartTagAddIn_Office2007_NET35 Properties to display the Project Designer.

  5. Select the Publish tab.

  6. Click Prerequisites. Notice that Microsoft Office 2007 Primary Interop Assemblies and Microsoft Visual Studio 2010 Tools for Office Runtime (x86 and x64) are checked (see Figure 5.)

    Figure 5. The Office 2007 PIAs and VSTO 2010 runtime are required to run the solution

    Office 2007 PIAs and VSTO runtime

    If the .NET Framework 3.5 is already on the user's computer, a complete install of Office 2007 installs the PIAs, so they will be present. If the PIAs are not present, the solution's setup routine will download and install them.

    Obviously, installing Office 2007 does not install the Visual Studio Tools for Office 2010 Runtime. This must be installed. The solution's setup routine will download and install this if it is not already present.

  7. Click Cancel to close the Prerequisites dialog box.

Version 2: Office 2007 Solutions That Target the .NET Framework 4

  1. In Visual Studio 2010, load the sample project, SmartTagAddIn_Office2007_NET4.sln.

  2. If you are using Visual Basic, click the Show All button in the Solution Explorer.

  3. Expand the References node in the Solution Explorer.

  4. Select Microsoft.Office.Interop.SmartTag.

    New in the .NET Framework 4 is the ability to embed type information for COM types directly into managed assemblies. Note that only the types and members used by the managed assembly are embedded. In

    Figure 6, you can see that the Embed Interop Types property for the SmartTag PIA is set to True. The type information will be embedded in the SmartTagAddIn_Office2007_NET4 assembly and therefore, users do not need the PIA installed on their computers.

    Figure 6. The COM types for SmartTags are embedded in the Word add-in assembly

    COMN types for SmartTags
  5. Select Microsoft.Office.Interop.Word. The Embed Interop Types property for this PIA is set to True.

  6. On the Project menu, select SmartTagAddIn_Office2007_NET4 Properties to display the Project Designer.

  7. Select the Publish tab.

  8. Click Prerequisites. Notice that Microsoft Office 2007 Primary Interop Assemblies is not checked (see Figure 7). Microsoft Visual Studio 2010 Tools for Office Runtime (x86 and x64) is checked and must be installed if it is not already present.

    Figure 7. The Office 2007 PIAs are not prerequisites in a solution that targets the .NET Framework 4

    Office 2007 Prerequisites
  9. Notice also that Microsoft .NET Framework 4 Client Profile (x86 and x64) is checked.

    The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications. It provides functionality for most client applications, including Windows Presentation Foundation (WPF), Windows Forms, Windows Communication Foundation (WCF), and ClickOnce features. This enables faster deployment and a smaller install package for applications that target the .NET Framework 4 Client Profile.

  10. Click Cancel to close the Prerequisites dialog box.

  11. If you are using Visual Basic, select the Compile tab of the Project Designer. Click Advanced Compile Options. In the Advanced Compiler Settings dialog box, notice that .NET Framework 4 Client Profile is selected in the Target framework drop-down list. Click Cancel to close the Advanced Compiler Settings dialog box.

  12. If you are using Visual C#, select the Application tab of the Project Designer. Notice that .NET Framework 4 Client Profile is selected in the Target framework drop-down list.

    By default, when you create an Office solution that targets the .NET Framework 4, Visual Studio targets the .NET Framework 4 Client Profile. If you are using parts of the .NET Framework that are not included in the Client Profile, you can select .NET Framework 4 from the Target framework drop-down list.

Version 3: Office 2010 Solutions That Target the .NET Framework 3.5

  1. In Visual Studio 2010, load the sample project, SmartTagAddIn_Office2010_NET35.sln.

  2. If you are using Visual Basic, click the Show All button in the Solution Explorer.

  3. Expand the References node in the Solution Explorer.

    Microsoft.Office.Interop.SmartTag and Microsoft.Office.Interop.Word are the Office 2010 versions of the primary interop assemblies that you saw in the previous two projects.

  4. On the Project menu, select SmartTagAddIn_Office2010_NET35 Properties to display the Project Designer.

  5. Select the Publish tab.

  6. Click Prerequisites. Notice that there is currently no Microsoft Office 2010 Primary Interop Assemblies item. Also notice that Microsoft Visual Studio 2010 Tools for Office Runtime (x86 and x64) is not checked (see Figure 8.)

    Figure 8. You do not need to list the VSTO 2010 Runtime as a prerequisite for the solution

    Office 2010 Prerequisites

    If the .NET Framework 3.5 is already on the user's computer, installing Office 2010 will install the PIAs, so they will be present. If the PIAs are not present, the solution's setup routine must download and install them. When Office 2010 ships, the PIAs are available for download from the Microsoft Web site. If you want the setup routine to download and install them, you must add them to the list in the Prerequisites dialog box. To do that, you can create a bootstrapper package. For more information, see Creating Bootstrapper Packages.

    When the user installs Office 2010 on a computer that has the .NET Framework 3.5 already installed, the Visual Studio 2010 Tools for Office Runtime is installed as well, along with the Office extensions for the .NET Framework 3.5. These extensions are the components that are required to run customizations that target the 3.5 version of the .NET Framework.

  7. Click Cancel to close the Prerequisites dialog box.

Version 4: Office 2010 Solutions That Target the .NET Framework 4

  1. In Visual Studio 2010, load the sample project, SmartTagAddIn_Office2010_NET4.sln.

  2. If you are using Visual Basic, click the Show All button in the Solution Explorer.

  3. Expand the References node in the Solution Explorer.

  4. Select Microsoft.Office.Interop.SmartTag. The Embed Interop Types property for this PIA is set to True.

  5. Select Microsoft.Office.Interop.Word. The Embed Interop Types property for this PIA is set to True.

  6. On the Project menu, select SmartTagAddIn_Office2010_NET4 Properties to display the Project Designer.

  7. Select the Publish tab.

  8. Click Prerequisites. Notice also that Microsoft .NET Framework 4 Client Profile (x86 and x64) is checked. As you saw previously, when you create an Office solution that targets the .NET Framework 4, Visual Studio targets the .NET Framework 4 Client Profile by default.

  9. Notice that there is currently no Microsoft Office 2010 Primary Interop Assemblies item. Also notice that Microsoft Visual Studio 2010 Tools for Office Runtime (x86 and x64) is not checked (see Figure 9).

    Figure 9. The VSTO 2010 Runtime is not a prerequisite for the solution by default

    VSTO 2010 runtime prerequisite

    As shown previously, by default you do not need the PIAs installed on the user's computer for a solution that targets the .NET Framework 4. The types and members are embedded in the solution's managed assembly.

    When Office 2010 is installed on a computer that has the .NET Framework 4, the Visual Studio 2010 Tools for Office Runtime are installed as well. However, by default, Office 2010 does not include the Office extensions for the .NET Framework 4. These extensions are the components that are required to run customizations that target version 4 of the .NET Framework. Therefore, you should check Microsoft Visual Studio 2010 Tools for Office Runtime (x86 and x64) in the Prerequisites dialog box. That will cause the setup routine to reinstall the Visual Studio runtime and also install the Office extensions.

  10. Click Cancel to close the Prerequisites dialog box.

  11. If you are using Visual Basic, select the Compile tab of the Project Designer. Click Advanced Compile Options. In the Advanced Compiler Settings dialog box, notice that .NET Framework 4 Client Profile is selected in the Target framework drop-down list. Click Cancel to close the Advanced Compiler Settings dialog box.

  12. If you are using Visual C#, select the Application tab of the Project Designer. Notice that .NET Framework 4 Client Profile is selected in the Target framework drop-down list.

To publish and install the solution

  1. In Visual Studio, on the Build menu, select Clean Solution.

  2. Select the Publish tab in the Project Designer.

    Figure 10. Use the Publish tab of the Project Designer to publish an Office solution

    Publish the solution
  3. In the Publishing Location Folder text box, enter a location where you want to publish the application.

  4. Click Publish Now to publish the solution.

  5. In the Windows Explorer, navigate to the publish folder.

    Figure 11. The contents of the publish folder

    Contents of the publish folder

    The publish folder contains the document and the Setup program. It also contains the deployment manifest (SmartTagAddIn_Office2010_NET4.vsto.) This describes how the application is deployed. It includes the location of the application manifest, and the version of the application that clients should run.

  6. Double-click the Application Files folder. This contains a SmartTagAddIn_Office2010_NET4_1_0_0_0 folder. This contains the files that are required to install version 1.0.0.0 of the solution.

  7. Double-click SmartTagAddIn_Office2010_NET4_1_0_0_0 folder.

    Figure 12. The contents of the SmartTagAddIn_Office2010_NET4_1_0_0_0 folder

    Contents of the folder

    This folder contains the customization assembly (SmartTagAddIn_Office2010_NET4.dll.deploy) and the assembly that contains base classes for the ThisAddIn and Ribbon class (Microsoft.Office.Tools.Common.v4.0.Utilities.dll.deploy). It also contains the deployment manifest (SmartTagAddIn_Office2010_NET4.vsto) and the application manifest (SmartTagAddIn_Office2010_NET4.dll.manifest.)

Read It

After you build an Office solution with Visual Studio and before you deploy it to end-users, you must make sure that end-users have the required software on their computers. Fortunately, the list of prerequisites is not long. It consists of the .NET Framework, the Visual Studio 2010 Tools for Office runtime and either Primary Interop Assemblies or the Office extensions for the .NET Framework, depending on which version of Office is used. You can use the Prerequisites dialog box to identify each of these.

See It

Watch the video

Watch video

Length: 00:10:32

Click to grab code

Grab the Code

Explore It

About the Author

Robert Green is a developer, writer, and trainer. He is a senior consultant with MCW Technologies. Robert is a Visual Studio Tools for the Office system MVP and is a co-author of AppDev courseware for Microsoft Visual Basic, Microsoft Visual C#, LINQ and Microsoft Windows Workflow Foundation. Before joining MCW, Robert worked at Microsoft as a Product Manager and also a Program Manager.

Show:
© 2014 Microsoft