System BadImageFormatException 可执行文件(.exe)或库(.dll)的格式无效。

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

CI流水线大约需要50分钟完成,大部分时间都被测试消耗掉了。有大量的单元测试和数据驱动测试。已决定并行运行测试,并根据本文档采取了相应的方法。在构建管道中并行运行测试

想法是将管道分为3个工作岗位。

  1. 建立工作 构建二进制文件,并将其发布到名称为pre-drop的工件上。

  2. 测试任务下载工件预投放,提取文件,使用VSTest@2任务并行运行测试。

  3. 发布招聘信息:发布要丢弃的工件(用于发布管道)。

不知道我是否能把我的想法变成.yml。

测试工作

- job : 'TestJob'
  pool:
    vmImage: windows-latest
  strategy:
    parallel: 2
  dependsOn: 'BuildJob'

  steps:

  - task: DownloadBuildArtifacts@0
    inputs:
      buildType: 'current'
      downloadType: 'single'
      artifactName: 'predrop'
      downloadPath: '$(System.ArtifactsDirectory)'

  - task: ExtractFiles@1
    inputs:
      archiveFilePatterns: '$(System.ArtifactsDirectory)/predrop/predrop.zip'
      destinationFolder: '$(System.ArtifactsDirectory)/predrop/Extpredrop'

  - task: VSTest@2
    inputs:
      testSelector: 'testAssemblies'
      testAssemblyVer2: |
       **\*tests.dll
       !**\*TestAdapter.dll
       !**\obj\**
      searchFolder: '$(System.ArtifactsDirectory)'
      vstestLocationMethod: 'location'
      vstestLocation: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\TestPlatform\'
      otherConsoleOptions: '/platform:x64 /Framework:.NETCoreApp,Version=v3.1'

问题是VSTest任务能识别&运行一些测试,但在其他测试中出错,在一些测试中出现以下错误。

System.BadImageFormatException : Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=3.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. 
Format of the executable (.exe) or library (.dll) is invalid.

第一个作业的二进制文件已经生成了Microsoft.Extensions.Logging.Abstractions.dll作为工件的一部分。

.net-core azure-devops xunit.net vstest microsoft-extensions-logging
1个回答
0
投票

该文件的 BadImageFormatException类 说这个异常是在以下情况下抛出的。

  • 一个DLL或可执行文件被加载为64位的程序集,但它包含32位的功能或资源。例如,它依赖于COM互操作或调用32位动态链接库的方法。

  • 为了解决这个异常,将项目的Platform target属性设置为x86(而不是x64或AnyCPU)并重新编译。

所以你可以尝试配置VSBuild任务,将项目重建为x86或x64。 看看这个类似的错误 这条.

如果以上改变平台不工作。你可以试试这个变通方法,在job中添加一个VSBuild任务来构建你的项目。TestJob 也。这样一来,就不需要了。下载摘取 岗中之物 TestJob. 对于下面的例子。

- job : 'TestJob'
  pool:
    vmImage: windows-latest
  strategy:
    parallel: 2
  dependsOn: 'BuildJob'

  steps:
  - task: VSBuild@1
    inputs:
      solution: '**/*.sln'
      platform: "any cpu"
      configuration: 'Release'

  - task: VSTest@2
    inputs:
      ...

你也可以看看 这条.

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