Office 主互操作程序集Office primary interop assemblies

若要在 Office 项目中使用 Microsoft Office 应用程序的功能,你必须使用该应用程序的主互操作程序集 (PIA)。To use the features of a Microsoft Office application from an Office project, you must use the primary interop assembly (PIA) for the application. PIA 使托管代码可与 Microsoft Office 应用程序基于 COM 的对象模型进行交互。The PIA enables managed code to interact with a Microsoft Office application's COM-based object model.

Note

有兴趣开发跨多个平台扩展 Office 体验的解决方案?Interested in developing solutions that extend the Office experience across multiple platforms? 查看新的 " Office 外接程序" 模型Check out the new Office Add-ins model. 与 VSTO 外接程序和解决方案相比, Office 外接程序的占用空间较小, 可以使用几乎任何 web 编程技术 (例如 HTML5、JavaScript、CSS3 和 XML) 生成它们。Office Add-ins have a small footprint compared to VSTO Add-ins and solutions, and you can build them by using almost any web programming technology, such as HTML5, JavaScript, CSS3, and XML.

创建新的 Office 项目时,Visual Studio 会添加对生成该项目所需的 PIA 的引用。When you create a new Office project, Visual Studio adds references to the PIAs that are required to build the project. 在某些情况下,你可能需要添加对其他 PIA 的引用(例如,如果你希望在 Microsoft Office Excel 项目中使用 Microsoft Office Word 的功能)。In some scenarios, you might need to add references to additional PIAs (for example, if you want to use a feature of Microsoft Office Word in a project for Microsoft Office Excel).

本主题描述在 Office 项目中使用 Microsoft Office PIA 的以下方面:This topic describes the following aspects of using the Microsoft Office PIAs in Office projects:

有关主互操作程序集的详细信息, 请参阅主互操作程序集For more information about primary interop assemblies, see Primary interop assemblies.

分隔主互操作程序集以生成和运行项目Separate primary interop assemblies to build and run projects

Visual Studio 在开发计算机上使用不同的 PIA 集。Visual Studio uses different sets of the PIAs on the development computer. 这些不同的程序集位于下列位置:These different sets of assemblies are in the following locations:

  • Program files 目录中的文件夹A folder in the program files directory

    当你编写代码和生成项目时,将使用这些程序集副本。These copies of the assemblies are used when you write code and build projects. Visual Studio 会自动安装这些程序集。Visual Studio installs these assemblies automatically.

  • 全局程序集缓存The global assembly cache

    这些程序集副本在某些开发任务期间(例如在运行或调试项目时)使用。These copies of the assemblies are used during some development tasks, such as when you run or debug projects. Visual Studio 不会安装和注册这些程序集;你必须自己安装和注册。Visual Studio does not install and register these assemblies; you must do this yourself.

Program files 目录中的主互操作程序集Primary interop assemblies in the program files directory

安装 Visual Studio 时,会将 PIA 自动安装到文件系统中全局程序集缓存之外的某个位置。When you install Visual Studio, the PIAs are automatically installed to a location in the file system, outside of the global assembly cache. 创建新项目时,Visual Studio 会自动将对这些 PIA 副本的引用添加到你的项目中。When you create a new project, Visual Studio automatically adds references to these copies of the PIAs to your project. Visual Studio 使用这些 PIA 副本(而非全局程序集缓存中的程序集)在开发和生成项目时解析类型引用。Visual Studio uses these copies of the PIAs, instead of the assemblies in the global assembly cache, to resolve type references when you develop and build your project.

这些 PIA 副本帮助 Visual Studio 避免在全局程序集缓存中注册 PIA 的不同版本时可能发生的多种开发问题。These copies of the PIAs help Visual Studio avoid several development issues that can occur when different versions of the PIAs are registered in the global assembly cache.

从 Visual Studio 2017 开始, 这些 Pia 副本安装在开发计算机上的下列共享位置:Starting with Visual Studio 2017, these copies of the PIAs are installed to following shared locations on the development computer:

  • *%ProgramFiles%\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA**%ProgramFiles%\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA*

  • (或 *% ProgramFiles (x86)% \ Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA* on 64 位操作系统)(or *%ProgramFiles(x86)%\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA* on 64-bit operating systems)

Note

对于较旧版本的 Visual Studio, 这些 Pia 将安装到该版本的 Visual Studio 的 *% ProgramFiles% 文件夹下的 Visual Studio Tools Office\PIA "文件夹中。For older versions of Visual Studio, these PIAs will be installed to the Visual Studio Tools for Office\PIA folder under the *%ProgramFiles% folder for that version of Visual Studio.
例如: *% ProgramFiles (x86)% \ Microsoft Visual Studio 14.0 \ Visual Studio Tools 用于 Office\PIA*For Example: *%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Visual Studio Tools for Office\PIA*

全局程序集缓存中的主互操作程序集Primary interop assemblies in the global assembly cache

若要执行某些开发任务,必须在开发计算机上的全局程序集缓存中安装并注册 PIA。To perform certain development tasks, the PIAs must be installed and registered in the global assembly cache on the development computer. 通常,在开发计算机上安装 Office 时会自动安装 PIA。Typically, the PIAs are installed automatically when you install Office on the development computer. 有关详细信息, 请参阅配置计算机以开发 Office 解决方案For more information, see Configure a computer to develop Office solutions.

若要运行 Office 解决方案,无需在最终用户计算机上安装 Office PIA。The Office PIAs are not required on end-user computers to run Office solutions. 有关详细信息, 请参阅设计和创建 Office 解决方案For more information, see Design and create Office solutions.

在单个项目中使用多个 Microsoft Office 应用程序的功能Use features of multiple Microsoft Office applications in a single project

Visual Studio 中的每个 Office 项目模板旨在与单个 Microsoft Office 应用程序配合使用。Every Office project template in Visual Studio is designed to work with a single Microsoft Office application. 若要使用多个 Microsoft Office 应用程序的功能,或者使用 Visual Studio 中没有项目的应用程序或组件的功能,必须添加对所需 PIA 的引用。To use features in multiple Microsoft Office applications, or to use features in an application or component that does not have a project in Visual Studio, you must add a reference to the required PIAs.

在大多数情况下, 应添加对 Visual Studio 安装在%ProgramFiles(x86)%\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\目录下的 pia 的引用。In most cases, you should add references to the PIAs that are installed by Visual Studio under the %ProgramFiles(x86)%\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\ directory. 这些版本的程序集显示在 "引用管理器" 对话框的 "框架" 选项卡上。These versions of the assemblies appear on the Framework tab of the Reference Manager dialog box. 有关详细信息,请参阅如何:通过主互操作程序集面向 Office 应用程序。For more information, see How to: Target Office applications through primary interop assemblies.

如果你在全局程序集缓存中安装并注册了 PIA,则这些版本的程序集显示在 “引用管理器” 对话框的 “COM” 选项卡上。If you have installed and registered the PIAs in the global assembly cache, these versions of the assemblies appear on the COM tab of the Reference Manager dialog box. 你应当避免添加对这些版本的程序集的引用,因为使用它们时可能会出现某些开发问题。You should avoid adding references to these versions of the assemblies, because there are some development issues that can occur when you use them. 例如,如果你在全局程序集缓存中注册了 PIA 的不同版本,则项目将自动绑定到你最后一次注册的程序集版本,即使在 “引用管理器” 对话框的 “COM” 选项卡上指定了其他程序集版本也是如此。For example, if you have registered different versions of the PIAs in the global assembly cache, your project will automatically bind to the version of the assembly that was registered last—even if you specify a different version of the assembly on the COM tab of the Reference Manager dialog box.

Note

添加一个引用某些程序集的程序集时,这些被引用的程序集将自动添加到项目中。Some assemblies are added to a project automatically when an assembly that references them is added. 例如, 当你添加对 Word、Excel、Outlook、Microsoft Forms 或 Graph 程序集的引用时, 将自动添加对Office .dll程序集和microsoft.For example, references to the Office.dll and Microsoft.Vbe.Interop.dll assemblies are added automatically when you add a reference to the Word, Excel, Outlook, Microsoft Forms, or Graph assemblies.

Microsoft Office 应用程序的主互操作程序集Primary interop assemblies for Microsoft Office applications

下表列出了可用于Office 2016Office 2016Office 2013Office 2013Office 2010Office 2010的主互操作程序集。The following table lists the primary interop assemblies that are available for Office 2016Office 2016, Office 2013Office 2013 and Office 2010Office 2010.


Office 应用程序或组件Office application or component 主互操作程序集名称Primary interop assembly name
Microsoft Access 14.0 对象库Microsoft Access 14.0 Object Library

Microsoft Access 15.0 对象库Microsoft Access 15.0 Object Library
Microsoft.Office.Interop.Access.dllMicrosoft.Office.Interop.Access.dll
Microsoft Office 14.0 Access 数据库引擎对象库Microsoft Office 14.0 Access Database Engine Object Library

Microsoft Office 15.0 Access 数据库引擎对象库Microsoft Office 15.0 Access Database Engine Object Library
Microsoft.Office.Interop.Access.Dao.dllMicrosoft.Office.Interop.Access.Dao.dll
Microsoft Excel 14.0 对象库Microsoft Excel 14.0 Object Library

Microsoft Excel 15.0 对象库Microsoft Excel 15.0 Object Library
Microsoft.Office.Interop.Excel.dllMicrosoft.Office.Interop.Excel.dll
Microsoft Graph 14.0 对象库(PowerPoint、Access 和 Word 将该对象库用于图形)Microsoft Graph 14.0 Object Library (used by PowerPoint, Access, and Word for graphs)

Microsoft Graph 15.0 对象库Microsoft Graph 15.0 Object Library
Microsoft.Office.Interop.Graph.dllMicrosoft.Office.Interop.Graph.dll
Microsoft InfoPath 2.0 类型库(仅用于 InfoPath 2007)Microsoft InfoPath 2.0 Type Library (for InfoPath 2007 only) Microsoft.Office.Interop.InfoPath.dllMicrosoft.Office.Interop.InfoPath.dll
Microsoft InfoPath XML 互操作程序集(仅用于 InfoPath 2007)Microsoft InfoPath XML Interop Assembly (for InfoPath 2007 only) Microsoft.Office.Interop.InfoPath.Xml.dllMicrosoft.Office.Interop.InfoPath.Xml.dll
Microsoft Office 14.0 对象库(Office 共享的功能)Microsoft Office 14.0 Object Library (Office shared functionality)

Microsoft Office 15.0 对象库(Office 共享的功能)Microsoft Office 15.0 Object Library (Office shared functionality)
office.dlloffice.dll
Microsoft Office Outlook 视图控件(在网页和应用程序中可用来访问收件箱)Microsoft Office Outlook View Control (can be used in Web pages and applications to access your Inbox) Microsoft.Office.Interop.OutlookViewCtl.dllMicrosoft.Office.Interop.OutlookViewCtl.dll
Microsoft Outlook 14.0 对象库Microsoft Outlook 14.0 Object Library

Microsoft Outlook 15.0 对象库Microsoft Outlook 15.0 Object Library
Microsoft.Office.Interop.Outlook.dllMicrosoft.Office.Interop.Outlook.dll
Microsoft PowerPoint 14.0 对象库Microsoft PowerPoint 14.0 Object Library

Microsoft PowerPoint 15.0 对象库Microsoft PowerPoint 15.0 Object Library
Microsoft.Office.Interop.PowerPoint.dllMicrosoft.Office.Interop.PowerPoint.dll
Microsoft Project 14.0 对象库Microsoft Project 14.0 Object Library

Microsoft Project 15.0 对象库Microsoft Project 15.0 Object Library
Microsoft.Office.Interop.MSProject.dllMicrosoft.Office.Interop.MSProject.dll
Microsoft Publisher 14.0 对象库Microsoft Publisher 14.0 Object Library

Microsoft Publisher 15.0 对象库Microsoft Publisher 15.0 Object Library
Microsoft.Office.Interop.Publisher.dllMicrosoft.Office.Interop.Publisher.dll
Microsoft SharePoint Designer 14.0 Web 对象引用库Microsoft SharePoint Designer 14.0 Web Object Reference Library Microsoft.Office.Interop.SharePointDesigner.dllMicrosoft.Office.Interop.SharePointDesigner.dll
Microsoft SharePoint Designer 14.0 Page 对象引用库Microsoft SharePoint Designer 14.0 Page Object Reference Library Microsoft.Office.Interop.SharePointDesignerPage.dllMicrosoft.Office.Interop.SharePointDesignerPage.dll
Microsoft 智能标记2.0 类型库说明:Excel 2010Excel 2010Word 2010Word 2010中弃用了智能标记。Microsoft Smart Tags 2.0 Type Library Note: Smart tags are deprecated in Excel 2010Excel 2010 and Word 2010Word 2010. Microsoft.Office.Interop.SmartTag.dllMicrosoft.Office.Interop.SmartTag.dll
Microsoft Visio 14.0 类型库Microsoft Visio 14.0 Type Library

Microsoft Visio 15.0 类型库Microsoft Visio 15.0 Type Library
Microsoft.Office.Interop.Visio.dllMicrosoft.Office.Interop.Visio.dll
Microsoft Visio 14.0 Save As Web 类型库Microsoft Visio 14.0 Save As Web Type Library

Microsoft Visio 15.0 Save As Web 类型库Microsoft Visio 15.0 Save As Web Type Library
Microsoft.Office.Interop.Visio.SaveAsWeb.dllMicrosoft.Office.Interop.Visio.SaveAsWeb.dll
Microsoft Visio 14.0 绘图控件类型库Microsoft Visio 14.0 Drawing Control Type Library

Microsoft Visio 15.0 绘图控件类型库Microsoft Visio 15.0 Drawing Control Type Library
Microsoft.Office.Interop.VisOcx.dllMicrosoft.Office.Interop.VisOcx.dll
Microsoft Word 14.0 对象库Microsoft Word 14.0 Object Library

Microsoft Word 15.0 对象库Microsoft Word 15.0 Object Library
Microsoft.Office.Interop.Word.dllMicrosoft.Office.Interop.Word.dll
Microsoft Visual Basic for Applications Extensibility 5.3Microsoft Visual Basic for Applications Extensibility 5.3 Microsoft.Vbe.Interop.dllMicrosoft.Vbe.Interop.dll

绑定重定向程序集Binding redirect assemblies

在全局程序集缓存中安装并注册 Office PIA(通过 Office,或通过为 PIA 安装可再发行组件包)时,绑定重定向程序集也只会安装在全局程序集缓存中。When you install and register the Office PIAs in the global assembly cache (either with Office or by installing the redistributable package for the PIAs), the binding redirect assemblies are also installed only in the global assembly cache. 这些程序集有助于确保在运行时加载主互操作程序集的正确版本。These assemblies help make sure that the correct version of the primary interop assemblies is loaded at runtime.

例如,当引用 Office 2010Office 2010 程序集的解决方案在装有同一主互操作程序集的 Office 2013Office 2013 版本的计算机上运行时,绑定重定向程序集会指示 .NET Framework.NET Framework 运行时加载 Office 2013Office 2013 版本的主互操作程序集。For example, when a solution that references a Office 2010Office 2010 assembly runs on a computer that has the Office 2013Office 2013 version of the same primary interop assembly, the binding redirect assembly instructs the .NET Framework.NET Framework runtime to load the Office 2013Office 2013 version of the primary interop assembly.

有关详细信息,请参阅如何:启用和禁用自动绑定重定向。For more information, see How to: Enable and disable automatic binding redirection.

请参阅See also