【问题标题】:Could not load file or assembly sapnco vstest Azure Pipelines无法加载文件或程序集 sapnco vstest Azure Pipelines
【发布时间】:2021-02-06 12:41:00
【问题描述】:

当使用发布阶段的自动化测试从 Azure Pipeline 中的测试计划运行测试时,我们遇到错误“无法加载文件或程序集 'sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23'或其依赖项之一。系统找不到指定的文件。"

由于这是一个 64 位的 dll,我们在 Vstest 任务中提供了 /Platform:x64 选项。以下是发布管道中 VsTest 任务的 yaml:

steps:
- task: VSTest@2
  displayName: 'VsTest - Test Run on Demand for ETL Tests'
  inputs:
    testSelector: testRun
    searchFolder: '$(System.DefaultWorkingDirectory)\_Development\bin\Release'
    vsTestVersion: toolsInstaller
    pathtoCustomTestAdapters: '$(System.DefaultWorkingDirectory)\_Development\packages\'
    runTestsInIsolation: false
    otherConsoleOptions: '/Platform:x64'
    platform: x64
    configuration: Release
  continueOnError: true

即使单独运行测试,我们也会遇到同样的错误。

Reflection LoaderExceptions 融合日志如下:

Reflection error message is: Could not load file or assembly 'sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23' or one of its dependencies. The system cannot find the file specified.
Fusion Log:
Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\AzAgent\A1\_work\_tool\VsTest\16.7.1\x64\tools\net451\Common7\IDE\Extensions\TestPlatform\testhost.x86.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23
 (Fully-specified)
LOG: Appbase = file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common
LOG: Initial PrivatePath = NULL
Calling assembly : <calling assembly>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\AzAgent\A1\_work\r1\a\_Development\bin\Release\<test dll>.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common/sapnco.DLL.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common/sapnco/sapnco.DLL.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common/sapnco.EXE.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common/sapnco/sapnco.EXE.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/bin/Release/sapnco.DLL.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/bin/Release/sapnco/sapnco.DLL.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/bin/Release/sapnco.EXE.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/bin/Release/sapnco/sapnco.EXE.

dll 存在于融合日志中尝试下载的位置。

我们不确定如何修复此错误。我们也将构建平台从 Any CPU 更改为 x64。问题的解决方法是什么?

【问题讨论】:

  • 您在运行测试之前是否恢复了软件包?
  • @KrzysztofMadej 包存在于 _Development\packages 文件夹中,并且该文件夹在自定义适配器路径中指定。这个包不存在于 packages.config 文件中,因此不会被 nuget 恢复。它是对包路径的引用。

标签: .net azure-devops azure-pipelines azure-pipelines-release-task


【解决方案1】:

无法加载文件或程序集 sapnco vstest Azure Pipelines

由于您从发布阶段运行测试,因此您应该确保程序集文件 sapnco.dll 在您的构建工件中,以便可以将其下载到发布管道。

您可以查看文件夹 C:/AzAgent/A1/_work/r1/a/_Development/bin/Release 以获取程序集文件 sapnco.dll

如果该 dll 文件不存在,则需要将其复制并发布为工件。

另一点是确保您使用的是包sapnco3.x64 而不是用于x64 的sapnco。

更新:

我仔细检查了你的测试任务后,发现你选择的测试使用的是Test run而不是Test assemblies,测试运行:

在设置环境以运行测试时使用此选项 从测试中心。 运行测试时不应使用此选项 在持续集成/持续部署 (CI/CD) 管道中

要解决此问题,请尝试使用Test assemblies

【讨论】:

  • sapnco.dll 包位于 C:/AzAgent/A1/_work/r1/a/_Development/bin/Release 文件夹中。有一个复制步骤,将 64 位 sapnco dll 从包文件夹复制到指定路径。
  • @AshwinHariharan,你是如何添加sapnco.dll的,直接将dll文件添加到项目中还是通过nuget包添加?请分享sapnco.dll的参考方的项目文件,并分享构建和发布管道配置。
  • 这是 nuget packages.config 文件中使用的包。在构建时,在 nuget 恢复期间,它会恢复到包文件夹。
  • task: VSBuild@1 inputs: solution: &lt;sln file&gt; vsVersion: '16.0' msbuildArgs: '$(msbuildFlags) /t:Rebuild /p:DeployOnBuild=true /p:CreatePackageOnPublish=True /p:ExcludeGeneratedDebugSymbol=true /p:PackageLocation="$(OutputDirtry)"' platform: 'Any CPU' configuration: Release clean: true restoreNugetPackages: true displayName: 'Build SCH' 这是 CI 构建配置。我们也尝试将 Any CPU 更改为 x64
  • 发布配置在帖子中指定
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-25
  • 2018-10-13
  • 2018-11-29
  • 2016-12-16
  • 1970-01-01
  • 1970-01-01
  • 2018-09-10
相关资源
最近更新 更多