Azure DevOps流水线单元测试与库依赖关系不工作。

问题描述 投票:0回答:1

如果一个C#项目的单元测试中使用了MS假货和第三方库,在 .dll 在我的单元测试项目中,我把它称为X。.dll 是在本地引用的,并被打包在 Azure GIT 中。现在,当使用 MS 托管代理通过 Azure DevOps 管道构建解决方案时,一切都能正常工作,但单元测试一直在每次测试中失败。

单元测试yaml看起来如下。

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*UnitTests*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'

错误:

System.IO.FileNotFoundException : Could not load file or assembly 'Y, Version=4.0.0.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. 系统无法找到指定的文件。

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 Class not registered (来自HRESULT的异常:0x80040154 (REGDB_E_CLASSNOTREG))。

我在网上查过这个错误,但找不到任何解决方法。

有谁知道如何让单元测试在MS Agent上工作?

Configuration Manager

unit-testing dll azure-devops azure-pipelines
1个回答
1
投票

我已经尝试将Y添加到项目中作为引用,产生同样的结果。

当你将 Y 添加到单元测试项目时,请确保项目文件中 dll 文件的路径是 相对路径:

  <ItemGroup>
    <Reference Include="Y">
      <HintPath>..\Y.dll</HintPath>
    </Reference>
  </ItemGroup>

并确认属性 复制本地 设为 True:

它的错误更改如下:......

似乎dll注册在3264位版本的windows注册表上,但应用程序使用的是不同位版本。试着将你的项目构建属性 Platform target从 Any CPUx86x64 根据你的系统,它可能会解决这个问题。

检查 同道中人 以了解更多细节。

希望对大家有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.