[TFS 2017.1] Build vNext Agent 不需要安装 VS IDE 也能 Build

TFS 2017 改变了 VSTest 的设定,也支持了测试涵盖率,微软渐渐的把功能慢慢的抽出来,不需要为了某个功能安装一大包的东西,安装体验变得很不一样,这里要分享 TFS 2017 不需要安装 VS IDE 也能建置的步骤


要Build VS2015 请看
https://dotblogs.com.tw/yc421206/2017/03/30/tfs2015_build_agent_without_install_vs2015

服用此贴时,请注意:

不安装 VS IDE 可能会有一些 TFS 建置步骤所对应的环境设定会失效,需要花额外的时间解决问题,如果你不想解决这些问题,最快的方式还是安装 VS IDE

开发环境

  • Windows Server 2016
  • SQL 2016 Devloper SP1
  • TFS 2017 Update1
  • VS 2017 Update1

安装步骤

  • #安装 .NET Target,选择正确的 .NET Developer Pack 版本
  • #安装 Agents for Visual Studio 2017
  • #安装 Build Tools for Visual Studio 2017
  • #重开机
  • #VisualStudio Capabilities
  • #新增 VSTest User Capabilities
  • #运行结果

安装 .NET Target,选择正确的 .NET Developer Pack 版本

https://www.microsoft.com/net/targeting

例如你是开发 .NET Framework 4 以上,那你就可以直接装最新的 4.6.2

 

安装 Agents for Visual Studio 2017

https://www.visualstudio.com/downloads/

下载方式如下图:

装完之后会多一个路径 C:Program Files (x86)Microsoft Visual Studio2017TestAgent,vstest.console.exe 会在这里面,完整路径如下:

C:Program Files (x86)Microsoft Visual Studio2017TestAgentCommon7IDECommonExtensionsMicrosoftTestWindowvstest.console.exe

安装 Build Tools for Visual Studio 2017

https://www.visualstudio.com/downloads/

下载方式如下图:

默认设是 Build Tools,里面包含 Windows 10 SDK(根据你的操作系统来决定要不要装,我选择不装也可以Build)、Microsoft Visual C++ Redistributable for Visual Studio 2017,大约 2.78 G

 

重开机

VisualStudio Capabilities

在 Agent Pool,就可以看到 Capabilities 已经有 VisualStudio,路径是 C:Program Files (x86)Microsoft Visual Studio2017BuildTools,如下图:

唯独不见 VSTest,原来 TFS2017 测试步骤 (Test Assemblies)没有支持 VS2017,如下图

估计运行建置应该也是会失败,哈哈,果不其然,如下图

依上篇 [TFS 2015.3] Build vNext 不需要安装 VS 2015 ,我们在 TFS 2017 的 VSTest Version 就可以选用 Visual Studio 2015

 

会出现这个问题是因为 Agent 在还没有安装Build Tool / Agent 就建立了

 

新增 VSTest User Capabilities

新增 Capability→VSTest |  C:Program Files (x86)Microsoft Visual Studio2017TestAgentCommon7IDECommonExtensionsMicrosoftTestWindow,存档。

然后在 VSTest Version 选择最新的版本

 

运行结果

很顺利的跑完建置跟测试,测试步骤 (Test Assemblies) 的 Build vNext 主控台消息如下:

2017-04-01T15:29:05.8112468Z ##[section]Starting: Test Assemblies release*test*.dll;-:obj
2017-04-01T15:29:05.8267078Z ==============================================================================
2017-04-01T15:29:05.8267078Z Task         : Visual Studio Test
2017-04-01T15:29:05.8267078Z Description  : Run tests with Visual Studio test runner
2017-04-01T15:29:05.8267078Z Version      : 1.0.84
2017-04-01T15:29:05.8267078Z Author       : Microsoft Corporation
2017-04-01T15:29:05.8267078Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=624539)
2017-04-01T15:29:05.8267078Z ==============================================================================
2017-04-01T15:29:05.8579588Z Preparing task execution handler.
2017-04-01T15:29:06.7329682Z Executing the powershell script: C:TfsBuildAgentsagent-1_work_tasksVSTest_ef087383-ee5e-42c7-9a53-ab56c98420f91.0.84VSTest.ps1
2017-04-01T15:29:07.5298441Z Testing container: 'REGISTRY::HKEY_CLASSES_ROOTCLSID{177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D}'
2017-04-01T15:29:07.5298441Z
2017-04-01T15:29:07.5298441Z
2017-04-01T15:29:07.5298441Z Exists.
2017-04-01T15:29:07.5298441Z
2017-04-01T15:29:07.5298441Z
2017-04-01T15:29:07.5298441Z Adding Visual Studio setup helpers.
2017-04-01T15:29:07.5298441Z
2017-04-01T15:29:07.5298441Z
2017-04-01T15:29:07.8423584Z Getting Visual Studio setup instances.
2017-04-01T15:29:07.8423584Z
2017-04-01T15:29:07.8423584Z
2017-04-01T15:29:07.8736315Z Found 2 instances.
2017-04-01T15:29:07.8736315Z
2017-04-01T15:29:07.8736315Z
2017-04-01T15:29:07.9048484Z
2017-04-01T15:29:07.9048484Z
2017-04-01T15:29:07.9048484Z Description   : Supports running automated tests and load tests remotely
2017-04-01T15:29:07.9048484Z DisplayName   : Visual Studio Test Agent 2017
2017-04-01T15:29:07.9048484Z Id            : 3179ff3e
2017-04-01T15:29:07.9048484Z InstallDate   : System.Runtime.InteropServices.ComTypes.FILETIME
2017-04-01T15:29:07.9048484Z Name          : VisualStudio/15.0.0+26228.12
2017-04-01T15:29:07.9048484Z Path          : C:Program Files (x86)Microsoft Visual Studio2017TestAgent
2017-04-01T15:29:07.9048484Z Version       : 15.0.26228.12
2017-04-01T15:29:07.9048484Z VersionString : 15.0.26228.12
2017-04-01T15:29:07.9048484Z
2017-04-01T15:29:07.9048484Z Description   : The Visual Studio Build Tools allows you to build native and
2017-04-01T15:29:07.9048484Z                 managed MSBuild-based applications without requiring the
2017-04-01T15:29:07.9048484Z                 Visual Studio IDE. There are options to install the Visual C++
2017-04-01T15:29:07.9048484Z                 compilers and libraries, MFC, ATL, and C++/CLI support.
2017-04-01T15:29:07.9048484Z DisplayName   : Visual Studio Build Tools 2017
2017-04-01T15:29:07.9048484Z Id            : 80a7fbfb
2017-04-01T15:29:07.9048484Z InstallDate   : System.Runtime.InteropServices.ComTypes.FILETIME
2017-04-01T15:29:07.9048484Z Name          : VisualStudio/15.0.0+26228.12
2017-04-01T15:29:07.9048484Z Path          : C:Program Files (x86)Microsoft Visual Studio2017BuildTools
2017-04-01T15:29:07.9048484Z Version       : 15.0.26228.12
2017-04-01T15:29:07.9048484Z VersionString : 15.0.26228.12
2017-04-01T15:29:07.9048484Z
2017-04-01T15:29:07.9048484Z
2017-04-01T15:29:07.9048484Z
2017-04-01T15:29:07.9048484Z
2017-04-01T15:29:07.9048484Z
2017-04-01T15:29:07.9048484Z
2017-04-01T15:29:07.9985943Z Testing leaf: 'C:Program Files (x86)Microsoft Visual Studio2017TestAgentCommon7IDECommonExtensionsMicrosoftTestWindowvstest.console.exe'
2017-04-01T15:29:07.9985943Z
2017-04-01T15:29:07.9985943Z
2017-04-01T15:29:08.0142193Z Exists.
2017-04-01T15:29:08.0142193Z
2017-04-01T15:29:08.0142193Z
2017-04-01T15:29:08.1079784Z Working folder: C:TfsBuildAgentsagent-1_work1s
2017-04-01T15:29:08.1079784Z Executing C:Program Files (x86)Microsoft Visual Studio2017TestAgentCommon7IDECommonExtensionsMicrosoftTestWindowvstest.console.exe "C:TfsBuildAgentsagent-1_work1sDbTestUnitTestProject1binReleaseMicrosoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll" "C:TfsBuildAgentsagent-1_work1sDbTestUnitTestProject1binReleaseMicrosoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" "C:TfsBuildAgentsagent-1_work1sDbTestUnitTestProject1binReleaseMicrosoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" "C:TfsBuildAgentsagent-1_work1sDbTestUnitTestProject1binReleaseMicrosoft.VisualStudio.TestPlatform.TestFramework.dll" "C:TfsBuildAgentsagent-1_work1sDbTestUnitTestProject1binReleaseMicrosoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll" "C:TfsBuildAgentsagent-1_work1sDbTestUnitTestProject1binReleaseUnitTestProject1.dll"  /EnableCodeCoverage /logger:trx /TestAdapterPath:"C:TfsBuildAgentsagent-1_work1s"
2017-04-01T15:29:08.4673784Z Microsoft (R) Test Execution Command Line Tool Version 15.0.26228.0
2017-04-01T15:29:08.4673784Z Copyright (c) Microsoft Corporation.  All rights reserved.
2017-04-01T15:29:08.4673784Z
2017-04-01T15:29:08.8892303Z Starting test execution, please wait...
2017-04-01T15:29:09.1704802Z Warning: Using Isolation mode to run the tests as diagnostic data adapters were enabled in the runsettings. Use the /inIsolation parameter to suppress this warning.
2017-04-01T15:29:19.7579936Z Warning: Input string was not in a correct format.
2017-04-01T15:29:19.7579936Z
2017-04-01T15:29:19.8999160Z Warning: Input string was not in a correct format.
2017-04-01T15:29:19.8999160Z
2017-04-01T15:29:22.2580046Z Passed   TestMethod1
2017-04-01T15:29:22.3830189Z Results File: C:TfsBuildAgentsagent-1_work1sTestResultsBuildService_TFS2017 2017-04-01 08_29_22.trx
2017-04-01T15:29:22.3830189Z
2017-04-01T15:29:22.3830189Z Attachments:
2017-04-01T15:29:22.3830189Z   C:TfsBuildAgentsagent-1_work1sTestResultsf3e1c542-ea21-4fac-8a4f-5c97becc15c7BuildService_TFS2017 2017-04-01 08_29_12.coverage
2017-04-01T15:29:22.3830189Z
2017-04-01T15:29:22.3830189Z Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
2017-04-01T15:29:22.3830189Z Test Run Successful.
2017-04-01T15:29:22.3830189Z Test execution time: 9.3606 Seconds
2017-04-01T15:29:22.6330284Z Publishing Test Results...
2017-04-01T15:29:23.9299611Z Test results remaining: 1
2017-04-01T15:29:24.3518646Z Published Test Run : http://tfs2017:8080/tfs/DefaultCollection/DemoLab/_TestManagement/Runs#runId=6&_a=runCharts
2017-04-01T15:29:24.3987197Z ##[section]Finishing: Test Assemblies release*test*.dll;-:obj

 这个场景只适用VS2017所建立的测试项目,若是别的版本所建立的测试项目,需要特定的 Agents 跟 Build Tools,如同这篇的作法 https://dotblogs.com.tw/yc421206/2017/03/30/tfs2015_build_agent_without_install_vs2015

VS2017 的版本来到了 15.0.26228.12,前两天才更新到 10,今天就到了12
VSTest 的测试结果 C:TfsBuildAgentsagent-1_work1sTestResultsBuildService_TFS2017 2017-04-01 08_29_22.trx
 没想到连测试涵盖率都来了 C:TfsBuildAgentsagent-1_work1sTestResultsf3e1c542-ea21-4fac-8a4f-5c97becc15c7BuildService_TFS2017 2017-04-01 08_29_12.coverage

若有谬误,烦请告知,新手发帖请多包涵

2010~2017 C# 第四季