Exercise 3: Removing the PIA Dependence from the Application

Office programmability relies on types from the Office Primary Interop Assembly (PIA) to be able to interface with the various applications in the office suite. In the past, this has dramatically impacted deployment of customized Office applications for a number of reasons. First, different versions of Office use different versions of the PIA, creating complexity for managing the assemblies. Secondly, IT personnel had to figure out deployment strategies to ensure required PIA resources were available across their support base. Additionally, deploying the PIA with an application resulted in a larger installation than necessary due to the extra, unused features.

Note:
Primary Interop Assemblies (PIAs) are a critical part of any .NET framework application needing to interface with COM components. A regular Interop Assembly is used for describing the COM types, allowing managed code to bind to the COM types at compile time. Interop Assemblies also help the CLR understand how those COM types should be marshaled at run time. The Primary Interop Assembly differs from regular Interop Assemblies in that it is the “official” holder of all type descriptions and is signed by the vendor to ensure its validity.

Development in Visual Studio 2010 eases these burdens by removing this PIA dependence from applications. When the dependency is removed, the compiler will import whatever types are needed by your application from the PIA directly into your application; you simply deploy your application knowing that all the PIA classes you need are included with your application’s assemblies.

Task 1 – Checking that PIA dependencies are removed by default

In Visual Studio 2010 PIA dependencies are removed by default, to verify this:

  1. Open Microsoft Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
  2. Open the OfficeApplication.sln solution file. By default, this file is located in the folder: %TrainingKitInstallFolder%\Labs\Dev10Office\Source\RemovingPIA\Begin\ and choose the language of your preference. Optionally, you can continue working the solution you created in the previous exercise.
  3. Expand the project’s References.
    1. In Visual Basic, you should select the OfficeApplication project node and click the Show All Files button in the Solution Explorer in order to see the References node.
  4. Right-Click on Microsoft.Office.Interop.Excel in your project’s references, and choose Properties.
  5. Notice that the value of Embed Interop Types is set to True.
  6. Right-click on Microsoft.Office.Interop.Word in your project’s references, and choose Properties.
  7. Notice that the value of Embed Interop Types is set to True.

Next Step

Summary