Continuous integration VSTest生成执行-未加载依赖项目程序集

Continuous integration VSTest生成执行-未加载依赖项目程序集,continuous-integration,azure-devops,azure-pipelines,vstest,Continuous Integration,Azure Devops,Azure Pipelines,Vstest,我已经创建了一个服务结构应用程序,并在解决方案中添加了一个MSTest项目来测试服务中的方法 为此,我在MSTest项目中添加了对HelloWorldAPI.dll的服务项目引用 在此之后,我在VisualStudioTeamServices(WASVSO)中创建了一个自动生成定义,并尝试通过该生成执行VisualStudio测试用例。但是,我得到以下错误: > Starting task: Test Assemblies **\*test*.dll;-:**\obj\** *******

我已经创建了一个服务结构应用程序,并在解决方案中添加了一个MSTest项目来测试服务中的方法

为此,我在MSTest项目中添加了对
HelloWorldAPI.dll
的服务项目引用

在此之后,我在VisualStudioTeamServices(WASVSO)中创建了一个自动生成定义,并尝试通过该生成执行VisualStudio测试用例。但是,我得到以下错误:

> Starting task: Test Assemblies **\*test*.dll;-:**\obj\**
******************************************************************************
Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.104.1\tasks\VSTest\1.0.50\VSTest.ps1
Working folder: C:\a\1
Executing C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "C:\a\1\s\POC\ServiceFabric\HelloWorld\UnitTestProject1\bin\Debug\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll" "C:\a\1\s\POC\ServiceFabric\HelloWorld\UnitTestProject1\bin\Debug\UnitTestProject1.dll"  /logger:trx
Microsoft (R) Test Execution Command Line Tool Version 14.0.25420.1
Copyright (c) Microsoft Corporation.  All rights reserved.
Starting test execution, please wait...
Failed   GetHelloWorldString
Error Message:
Unable to create instance of class HelloWorld.Test.ProductContollerTest. Error: System.BadImageFormatException: Could not load file or assembly 'HelloWorldAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format..
Stack Trace:
at HelloWorld.Test.ProductContollerTest..ctor()

 - ***Error Message:***

*
**

> Unable to create instance of class
> HelloWorld.Test.ProductContollerTest. Error:
> System.BadImageFormatException: Could not load file or assembly
> 'HelloWorldAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
> or one of its dependencies. An attempt was made to load a program with
> an incorrect format..

**
*
请在团队服务中找到以下附加配置详细信息:


是否可以在VSTest执行步骤中加载相关(项目)程序集?

我来不及回答这个问题。但今天我面临同样的问题,所以我想在这里分享我的解决方案。它可能会帮助某人。
注意-我正在使用Visual Studio 2017。
对我来说,这是因为程序集/项目之间使用的处理器体系结构不一致(32位/64位)。
为了解决这个问题,我将所有项目的体系结构设置为64位(x64)。您可以通过在解决方案资源管理器中右键单击解决方案,然后单击
属性
配置属性
并单击
配置管理器
按钮来完成此操作。
接下来,我将测试的默认处理器体系结构设置为x64。您可以通过单击
测试
菜单>
测试设置
默认处理器体系结构
x64


确保您正在执行以正确路径生成的库-\bin\x64\Release\mytests.dll

如果直接在本地计算机上运行测试,结果如何?如何添加引用?项目引用(右键单击项目=>添加引用=>项目)或二进制引用(右键单击项目=>添加引用=>浏览器=>查找dll文件)?在这里发布详细的测试代码,或者在OneDrive上共享一个简单的项目。我也有这个问题,它也适用于我的本地机器。如果使用适当的测试运行程序直接在DLL上运行
vstest.console.exe
,则会遇到此错误。可用于
dotnet test
,但在其他情况下找不到可执行文件来运行测试。您使用的是哪个服务模板?如何添加测试项目以及详细的测试代码是什么?当您试图针对不正确的平台体系结构时,BadImageFormatException往往会发生。尝试将平台从x64更改为x86
Stack Trace:
at HelloWorld.Test.ProductContollerTest..ctor()
Failed   GetAllProductListTest
Test Run Failed.
Results File: C:\a\1\TestResults\buildguest_TASKAGENT5-0026 2016-08-22 08_48_07.trx
Total tests: 2. Passed: 0. Failed: 2. Skipped: 0.
Test execution time: 0.4165 Seconds
System.Exception: VSTest Test Run failed with exit code: 1
Publishing Test Results...
Test results remaining: 2
Published Test Run : https://jci.visualstudio.com/Project%20-%20Microservices/_TestManagement/Runs#runId=3191&_a=runCharts