.net core 可执行文件(.exe)或库(.dll)的系统BadImageFormatException格式无效

.net core 可执行文件(.exe)或库(.dll)的系统BadImageFormatException格式无效,.net-core,azure-devops,xunit.net,vstest,microsoft-extensions-logging,.net Core,Azure Devops,Xunit.net,Vstest,Microsoft Extensions Logging,CI管道大约需要50分钟才能完成,大部分时间用于测试。有大量的单元测试和数据驱动测试。已决定并行运行测试,并基于此文档采取了相应的方法 想法是将管道分成3个工作 构建作业:构建二进制文件并使用 姓名预先删除 测试作业:下载工件预放置,提取文件,使用VSTest@2任务 发布作业:发布要删除的工件(用于发布管道) 不确定我是否能把我的想法写进.yml 测试作业 - job : 'TestJob' pool: vmImage: windows-latest strategy:

CI管道大约需要50分钟才能完成,大部分时间用于测试。有大量的单元测试和数据驱动测试。已决定并行运行测试,并基于此文档采取了相应的方法

想法是将管道分成3个工作

  • 构建作业:构建二进制文件并使用 姓名预先删除

  • 测试作业:下载工件预放置,提取文件,使用VSTest@2任务

  • 发布作业:发布要删除的工件(用于发布管道)

  • 不确定我是否能把我的想法写进.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.Abstractations.dll作为工件的一部分。

    的文档称此异常在以下场景中引发:

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

    • 要解决此异常,请将项目的平台目标属性设置为x86(而不是x64或AnyCPU),然后重新编译

    因此,您可以尝试配置VSBuild任务以将项目重建为x86或x64。请查看中的类似错误

    如果出现上述情况,则更换平台不起作用。您也可以尝试使用此解决方法添加VSBuild任务,以在jobTestJob中构建项目。这样,就不需要下载和提取jobTestJob中的工件。例如:

    - 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:
          ...
    

    您也可以查看。

    所有配置似乎都很好,因此它可以是一个单独的配置。如果您与我们共享您的YAML文件,这将非常方便。随意猜测:related?为测试作业更新了YAML