【发布时间】:2020-05-26 16:24:01
【问题描述】:
如果一个 C# 项目的单元测试使用 MS fakes 和 .dll 中的第 3 方库,我将引用为 X。在我的单元测试项目中,.dll 在本地引用并打包在 Azure吉特。现在,当使用 MS 托管代理通过 Azure DevOps 管道构建解决方案时,一切正常,但单元测试在每次测试中都会失败。
单元测试yaml如下:
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*UnitTests*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
错误:
System.IO.FileNotFoundException:无法加载文件或程序集“Y,版本=4.0.0.0,Culture=neutral,PublicKeyToken=...”或其依赖项之一。系统找不到指定的文件。
Y 是另一个.dll,我假设第一个库依赖于它,尽管使用dumpbin /dependents X.dll 不会显示它。我尝试将 Y 添加到项目中作为参考,产生相同的结果。我尝试使用以下 Powershell 脚本来添加它:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$dllpath = 'dll'
$files = Get-ChildItem -Path $dllpath -Name
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
Foreach ($file in $files)
{
$publish.GacInstall($dllpath + "\" + $file)
}
将错误更改如下:
System.Runtime.InteropServices.COMException:检索具有 CLSID {...} 的组件的 COM 类工厂失败,原因是以下错误:80040154 未注册类(来自 HRESULT 的异常:0x80040154 (REGDB_E_CLASSNOTREG))。
我已经在线检查了错误,但找不到任何解决问题的方法。
有人知道如何让单元测试在 MS Agent 上运行吗?
【问题讨论】:
标签: unit-testing dll azure-devops azure-pipelines