Azure Pipeline自托管代理安装Microsoft.TestPlatform后VSTest任务报错
在无Visual Studio的自托管Azure Pipeline代理上配置VSTest任务的解决方案
直接指定VSTest控制台路径
VSTest@3任务默认会扫描Visual Studio的默认安装路径,未安装VS时需手动指定已下载的vstest.console.exe路径。修改YAML任务配置,使用path模式指定绝对路径:
- task: VSTest@3 inputs: testSelector: 'testAssemblies' testAssemblyVer2: | **\*test*.dll !**\*TestAdapter.dll !**\obj\** vstestLocationMethod: 'path' vstestPath: 'C:\Temp\Microsoft.TestPlatform.17.11.1\tools\net462\Common7\IDE\Extensions\TestPlatform\vstest.console.exe' platform: '$(buildPlatform)' configuration: '$(buildConfiguration)'
配置专用环境变量
放弃无效的vstest环境变量,设置VSTEST_CLI_PATH系统环境变量指向vstest.console.exe:
- 变量名:
VSTEST_CLI_PATH - 变量值:
C:\Temp\Microsoft.TestPlatform.17.11.1\tools\net462\Common7\IDE\Extensions\TestPlatform\vstest.console.exe
设置完成后重启Azure Pipeline代理服务,任务会优先读取该环境变量指定的路径,无需依赖Visual Studio检测。
改用命令行直接调用
绕开VSTest任务的VS检测逻辑,直接用CmdLine任务调用vstest.console.exe执行测试:
- task: CmdLine@2 inputs: script: | "C:\Temp\Microsoft.TestPlatform.17.11.1\tools\net462\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" **\*test*.dll /Platform:x64 /Configuration:Release
验证TestPlatform包完整性
若以上方法无效,重新安装NuGet包并清理缓存,确保文件无缺失:
nuget install microsoft.testplatform -Version 17.11.1 -OutputDirectory C:\Temp -NoCache
安装后检查目标路径下的vstest.console.exe及相关依赖文件是否齐全。
内容的提问来源于stack exchange,提问作者bingbong
相关产品推荐
相关产品推荐

