在 VSTS 上使用代理 "Hosted VS2017" 在测试步骤中产生错误

Using Agent "Hosted VS2017" on VSTS yields error in test step

到目前为止,我的构建定义配置如下:Default agent queue = Hosted 和构建解决方案步骤 Visual Studio Version = Visual Studio 2015。构建 运行 到目前为止还不错。

现在我正准备在我的开发机器上转移到 Visual Studio 2017,我想看看 VSTS 是否仍然能够 运行 我的构建成功。

因此我切换到 Default agent queue = Hosted VS2017 并在构建解决方案步骤中切换到 Visual Studio Version = Visual Studio 2017

不幸的是,我在测试程序集步骤中遇到以下错误。我正在使用 xUnit.net 进行单元测试。我目前没有使用.Net Core。

Finishing: Build solution $/tfs1/Apps/Base/Base.sln
********************************************************************
Starting: Test Assemblies **\debug\*test.dll;-:**\obj\**
********************************************************************
Task         : Visual Studio Test
Description  : Run tests with Visual Studio test runner
Version      : 1.0.84
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=624539)

Preparing task execution handler.
Executing the powershell script: C:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9.0.84\VSTest.ps1

No results found to publish.

System.Management.Automation.CmdletInvocationException: Unable to determine the location of vstest.console.exe ---> System.IO.FileNotFoundException: Unable to determine the location of vstest.console.exe
   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeVSTestCmdlet.GetVsTestLocation()
   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeVSTestCmdlet.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at Microsoft.TeamFoundation.DistributedTask.Handlers.LegacyVSTSPowerShellHost.VSTSPowerShellHost.Main(String[] args)

LegacyVSTSPowerShellHost.exe completed with return code: -1.
********************************************************************
Finishing: Test Assemblies **\debug\*test.dll;-:**\obj\**

VS2017 目前在 VSTS 中还没有完全支持吗?

对于新的构建定义(托管 VS2017 代理),您可以使用 .NET Core 任务和 Publish Test Results 任务来代替Visual Studio 测试任务。详细设置如下:

.NET 核心

命令:test

Project(s): 指定测试csproj文件,如**/*Tests/*.csproj

参数:--configuration $(BuildConfiguration)

发布测试结果

测试结果格式:VSTest

测试结果文件:**/TEST-*.xml

您需要将 Visual Studio 测试 step/task 的 VSTest 版本更改为最新版本。