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

8

本文介绍了在构建服务器上使用 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 进行单元测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14