在构建服务器上使用 Microsoft.Office.Interop dll 进行单元测试失败

Unit test with Microsoft.Office.Interop dll fails on build server(在构建服务器上使用 Microsoft.Office.Interop dll 进行单元测试失败)

本文介绍了在构建服务器上使用 Microsoft.Office.Interop dll 进行单元测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个单元测试.被测代码引用了 Microsoft.Office.Interop.Excel.dll.

I've written a unit test. The code under test references Microsoft.Office.Interop.Excel.dll.

测试在我的机器上运行良好,但在构建服务器上失败.它在 Excel 应用程序被实例化的那一行失败:

The test runs fine on my machine but fails on the build server. It fails on the line where the Excel application is instantiated:

var application = new Application { Visible = Visible };

错误是:

System.Runtime.InteropServices.COMException: 
Retrieving the COM class factory for component with CLSID 
{00024500-0000-0000-C000-000000000046} failed due to the following error:
80040154 Class not registered

这是否意味着我必须在我的构建服务器上安装可再发行主互操作程序集?如果是这样,我是否还需要在构建服务器上安装 Excel?

Does this mean I have to install the Redistributable Primary Interop Assemblies on my build server? And if so, do I also need to install Excel on the build server?

Microsoft.Office.Interop.Excel.dll 包含在我的解决方案中,并从那里引用.

Microsoft.Office.Interop.Excel.dll is included in my solution and it is referenced from there.

推荐答案

您需要为该版本安装 Office 和主互操作程序集,或 Visual Studio 才能使其正常工作.在 CI 环境中运行时您可能会遇到 COM 问题,如果您可以重组测试以避免使用 Office Interop,我强烈推荐它.

You'll need to install Office and the Primary Interop Assemblies for that version, or Visual Studio to get this to work. You might run into COM issues with running in a CI environment, and if you can restructure your tests to avoid using Office Interop, I'd highly recommend it.

这篇关于在构建服务器上使用 Microsoft.Office.Interop dll 进行单元测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在构建服务器上使用 Microsoft.Office.Interop dll 进行单元测试失败

基础教程推荐