[TFS 2017.1] Build vNext 不需要安裝 VS IDE

TFS 2017 改變了 VSTest 的設定,也支援了測試涵蓋率,微軟漸漸的把功能慢慢的抽出來,不需要為了某個功能安裝一大包的東西,安裝體驗變得很不一樣,這裡要分享 TFS 2017 不需要安裝 VS IDE 也能建置的步驟

開發環境

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

安裝步驟

安裝 .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 Studio\2017\TestAgent,vstest.console.exe 會在這裡面,完整路徑如下:

C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.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 Studio\2017\BuildTools\,如下圖:

 

唯獨不見 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 Studio\2017\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow,存檔。

 

然後在 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:\TfsBuildAgents\agent-1\_work\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\1.0.84\VSTest.ps1
2017-04-01T15:29:07.5298441Z Testing container: 'REGISTRY::HKEY_CLASSES_ROOT\CLSID\{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 Studio\2017\TestAgent
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 Studio\2017\BuildTools
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 Studio\2017\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.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:\TfsBuildAgents\agent-1\_work\1\s
2017-04-01T15:29:08.1079784Z Executing C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "C:\TfsBuildAgents\agent-1\_work\1\s\DbTest\UnitTestProject1\bin\Release\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll" "C:\TfsBuildAgents\agent-1\_work\1\s\DbTest\UnitTestProject1\bin\Release\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" "C:\TfsBuildAgents\agent-1\_work\1\s\DbTest\UnitTestProject1\bin\Release\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" "C:\TfsBuildAgents\agent-1\_work\1\s\DbTest\UnitTestProject1\bin\Release\Microsoft.VisualStudio.TestPlatform.TestFramework.dll" "C:\TfsBuildAgents\agent-1\_work\1\s\DbTest\UnitTestProject1\bin\Release\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll" "C:\TfsBuildAgents\agent-1\_work\1\s\DbTest\UnitTestProject1\bin\Release\UnitTestProject1.dll"  /EnableCodeCoverage /logger:trx /TestAdapterPath:"C:\TfsBuildAgents\agent-1\_work\1\s"
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:\TfsBuildAgents\agent-1\_work\1\s\TestResults\BuildService_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:\TfsBuildAgents\agent-1\_work\1\s\TestResults\f3e1c542-ea21-4fac-8a4f-5c97becc15c7\BuildService_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:\TfsBuildAgents\agent-1\_work\1\s\TestResults\BuildService_TFS2017 2017-04-01 08_29_22.trx
 沒想到連測試涵蓋率都來了 C:\TfsBuildAgents\agent-1\_work\1\s\TestResults\f3e1c542-ea21-4fac-8a4f-5c97becc15c7\BuildService_TFS2017 2017-04-01 08_29_12.coverage

 

若有謬誤,煩請告知,新手發帖請多包涵

2010~2015 C# 第四季