分发需要 Microsoft.Office.Interop.Excel 的应用程序

Distribution of an application that requires Microsoft.Office.Interop.Excel

我有一个引用 Microsoft.Office.Interop.Excel

的 c# (VS 2015) 应用程序

我的代码包括 oXL = new Microsoft.Office.Interop.Excel.Application(); 以及上述参考。

如果我在一台已经安装了 Office 2013 和 .Net 4.0 的机器上编译并安装了该应用程序,但是当我搜索那台计算机时,我在任何地方都找不到 Microsoft.Office.Interop.Excel.dll,我想这就是我想要的需要。

我看到了here:

By default, PIA’s are embedded in your solution when you build it so you don’t have to distribute PIAs to users as a prerequisite to using your VSTO Add-in or customization.

当我构建我的应用程序时,我没有将 Microsoft.Office.Interop.Excel.dll 包含在我的 Release 文件夹中(就像我对其他引用的 .dll 所做的那样)。

我是否需要手动添加它,或者是安装它以同时安装 Microsoft 的 Office Primary Interop Assemblies Redistributable 的唯一方法吗?

Jason,据我所知,您可以select安装您的应用程序所需的版本和 Office 包。

如果您正在使用 Visual Studio,您可以转到(您的应用程序的)设置并插入依赖项。

检查这些链接:

Deployment and Dependencies

How to: Create and Remove Project Dependencies

Jason,您还必须引用 MICROSOFT OFFICE XX.X OBJECT LIBRARY。 XX.X 是你在那里的版本。

当您的项目 运行 在客户端时,VS 将在 GAC_MSIL 中搜索以查看 he/she 那里是否有 Office。

不要尝试添加 EXCEL 库,因为它不会起作用。您的用户必须对您的代码有 Office 运行.

转到引用的属性并将 copylocal 设置为 true。 Interop 库默认将它们设置为 false。

这将在您构建项目时复制 DLL。

The Copy Local property (corresponding to CopyLocal) determines whether a reference is copied to the local bin path.

At run time, a reference must be located in either the Global Assembly Cache (GAC) or the output path of the project. If this property is set to true, the reference is copied to the output path of the project at run time.

要更深入地了解复制本地,请参阅 msdn

.NET 应用程序将在全局程序集中查找 dll 并动态绑定到任何合适的 dll。

DLL = 动态链接库

不同版本的 office 和不同平台(32 位与 64 位)有不同的 dll。 简而言之,不要在你的包中包含 dll。 在未安装 office 的情况下捕获异常。