Azure DevOps 2019 Server 无法执行具有代码覆盖率的测试
Azure DevOps 2019 Server failed on executing tests with code coverage
现状:
使我们的 Azure DevOps 2019 Server(代理) 能够构建 ASP.NET Core 3 和 .Net Core 3 应用程序,我们在其上安装了 Build Tools for Visual Studio 2019(expander Tools for Visual Studio 2019)。这不是最佳做法,但 Azure DevOps 2019 服务器和代理安装在同一台计算机上。
除了收集编码器覆盖率外,一切都按预期进行。构建了应用程序并提供了工件。我们可以确认,发布后的所有工件都按预期工作。
就像已经提到的那样,除了代码覆盖之外一切都很好。
要构建的应用程序是 .NET Framework 4.6.2 应用程序,并且是在 VS 2019 构建工具安装之前构建的,在代理上使用 VS 2017 Enterprise 成功构建。
为了测试,我们在 Visual Studio build
任务之后,在构建管道中使用带有 Visual Studio Test
的 MSTest。测试任务配置如下:
variables:
SolutionRootDirectory: 'MySolutionRoot'
SettingsFilePath: ''
BuildPlatform: 'Any CPU'
BuildConfiguration: 'Release'
steps:
- task: VSTest@2
displayName: 'Test Assemblies: $(BuildConfiguration)'
inputs:
testAssemblyVer2: |
**/*Test?(s).dll
!**/obj/**
searchFolder: '$(SolutionRootDirectory)'
runSettingsFile: '$(SettingsFilePath)'
codeCoverageEnabled: true
testRunTitle: 'Test run: $(SolutionRootDirectory)\*.sln'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
diagnosticsEnabled: true
collectDumpOn: always
rerunFailedTests: false
所有测试都已成功执行,但任务失败并显示以下消息:
##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
##[error]Error: The process 'C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\Common7\IDE\Extensions\TestPlatform\vstest.console.exe' failed with exit code 1
Publishing test results to test run '11901'
Test results remaining: 260. Test run id: 11901
##[error]VsTest task failed.
检查整个日志后,我发现了以下消息:
Data collector 'Code Coverage' message: Data collector 'Code Coverage' failed to provide initialization information. Error: System.TypeInitializationException: The type initializer for 'Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop' threw an exception. ---> Microsoft.VisualStudio.Diagnostics.Common.InvariantException: Failed to load IntelliTrace Profiler binary or failed to locate functions.
...以及下面的几行:
---> System.ComponentModel.Win32Exception: The system cannot find the path specified
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.Diagnostics.Common.Check.Throw[XT](String message, Func`1 innerEx)
at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop.ThrowInvariantExceptionOnZeroPtr(IntPtr ptr, String message)
at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop.InitInterop()
at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop..cctor()
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop.get_InteropInterface()
at Microsoft.VisualStudio.Diagnostics.Logging.LoggingConfig.Publish()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.InitiateCollection()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.GetEnvironmentVariables()
at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector.GetEnvironmentVariables()
at Microsoft.VisualStudio.TestPlatform.Common.DataCollector.DataCollectorInformation.SetTestExecutionEnvironmentVariables()
at Microsoft.VisualStudio.TestPlatform.Common.DataCollector.DataCollectionManager.GetEnvironmentVariables(Boolean& unloadedAnyCollector).
问题
有人知道问题出在哪里吗?
我想,也许我们必须安装 Agents for Visual Studio 2019(expander Tools for Visual Studio 2019),但我不确定这是否是正确的方法。此外,我找不到任何有意义的信息,我们必须使用哪个安装包 - Agent
或 Controller
.
过去,大多数时候,完成了完全 Visual Studio 企业安装,以获得代理的完整功能集。但我想要一种更干净的方法,只想安装需要的包,避免为构建代理使用企业许可证。
非常欢迎提出想法、方法和最佳实践。
非常感谢您的帮助。
应用解决方案
嗯,经过大量研究和阅读最佳实践后,最实用和最有针对性的解决方案是在 build agent
上安装 Visual Studio 2019 Enterprise
。这是我的第一种方法,但提出了寻找另一种解决方案的问题,以避免在构建代理上安装整个 VS 2019 Enterprise。
它包含所有需要的程序集,代码覆盖率只是企业版的一部分。
我更喜欢该解决方案,因为不需要修改构建管道。否则,必须修改所有现有构建管道以匹配其他建议的解决方案。
如果可以接受编辑现有管道,下面列出了其他建议的解决方案。
所有建议的解决方案:
- 使用
Coverlet
(Coverlet.MsBuild) by installing it via NuGet into test projects and importing its results (maybe in combination use with ReportGenerator
- 正在安装
Test Agent/Controller
并在构建管道的 MSTest 任务中引用其 vstest.console.exe
- 将所需的二进制文件复制到构建代理上的相关目录
感谢您的建议和投入的时间。
使用 Visual Studio Test Platform Installer task 对我有用。
只需确保将 vsTestVersion
更改为 toolsInstaller
- task: VisualStudioTestPlatformInstaller@1
inputs:
packageFeedSelector: 'nugetOrg'
versionSelector: 'specificVersion'
testPlatformVersion: '16.11.0'
- task: VSTest@2
inputs:
...
vsTestVersion: 'toolsInstaller'
codeCoverageEnabled: true
(测试版本 16.11.0,3 小时前发布,不确定之前是否可用)
我有一个缺点,以前我可以使用一个 variable/parameter 来设置 VSTest 和 VSBuild 版本,因为它们都有使用相同格式(15.0、16.0、最新)的版本参数,但工具安装程序需要一个特定的版本,所以如何保持同步并不简单,但也不清楚我们是否需要,也许不需要。
现状:
使我们的 Azure DevOps 2019 Server(代理) 能够构建 ASP.NET Core 3 和 .Net Core 3 应用程序,我们在其上安装了 Build Tools for Visual Studio 2019(expander Tools for Visual Studio 2019)。这不是最佳做法,但 Azure DevOps 2019 服务器和代理安装在同一台计算机上。
除了收集编码器覆盖率外,一切都按预期进行。构建了应用程序并提供了工件。我们可以确认,发布后的所有工件都按预期工作。
就像已经提到的那样,除了代码覆盖之外一切都很好。
要构建的应用程序是 .NET Framework 4.6.2 应用程序,并且是在 VS 2019 构建工具安装之前构建的,在代理上使用 VS 2017 Enterprise 成功构建。
为了测试,我们在 Visual Studio build
任务之后,在构建管道中使用带有 Visual Studio Test
的 MSTest。测试任务配置如下:
variables:
SolutionRootDirectory: 'MySolutionRoot'
SettingsFilePath: ''
BuildPlatform: 'Any CPU'
BuildConfiguration: 'Release'
steps:
- task: VSTest@2
displayName: 'Test Assemblies: $(BuildConfiguration)'
inputs:
testAssemblyVer2: |
**/*Test?(s).dll
!**/obj/**
searchFolder: '$(SolutionRootDirectory)'
runSettingsFile: '$(SettingsFilePath)'
codeCoverageEnabled: true
testRunTitle: 'Test run: $(SolutionRootDirectory)\*.sln'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
diagnosticsEnabled: true
collectDumpOn: always
rerunFailedTests: false
所有测试都已成功执行,但任务失败并显示以下消息:
##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
##[error]Error: The process 'C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\Common7\IDE\Extensions\TestPlatform\vstest.console.exe' failed with exit code 1
Publishing test results to test run '11901'
Test results remaining: 260. Test run id: 11901
##[error]VsTest task failed.
检查整个日志后,我发现了以下消息:
Data collector 'Code Coverage' message: Data collector 'Code Coverage' failed to provide initialization information. Error: System.TypeInitializationException: The type initializer for 'Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop' threw an exception. ---> Microsoft.VisualStudio.Diagnostics.Common.InvariantException: Failed to load IntelliTrace Profiler binary or failed to locate functions.
...以及下面的几行:
---> System.ComponentModel.Win32Exception: The system cannot find the path specified
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.Diagnostics.Common.Check.Throw[XT](String message, Func`1 innerEx)
at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop.ThrowInvariantExceptionOnZeroPtr(IntPtr ptr, String message)
at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop.InitInterop()
at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop..cctor()
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop.get_InteropInterface()
at Microsoft.VisualStudio.Diagnostics.Logging.LoggingConfig.Publish()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.InitiateCollection()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.GetEnvironmentVariables()
at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector.GetEnvironmentVariables()
at Microsoft.VisualStudio.TestPlatform.Common.DataCollector.DataCollectorInformation.SetTestExecutionEnvironmentVariables()
at Microsoft.VisualStudio.TestPlatform.Common.DataCollector.DataCollectionManager.GetEnvironmentVariables(Boolean& unloadedAnyCollector).
问题
有人知道问题出在哪里吗?
我想,也许我们必须安装 Agents for Visual Studio 2019(expander Tools for Visual Studio 2019),但我不确定这是否是正确的方法。此外,我找不到任何有意义的信息,我们必须使用哪个安装包 - Agent
或 Controller
.
过去,大多数时候,完成了完全 Visual Studio 企业安装,以获得代理的完整功能集。但我想要一种更干净的方法,只想安装需要的包,避免为构建代理使用企业许可证。
非常欢迎提出想法、方法和最佳实践。 非常感谢您的帮助。
应用解决方案
嗯,经过大量研究和阅读最佳实践后,最实用和最有针对性的解决方案是在 build agent
上安装 Visual Studio 2019 Enterprise
。这是我的第一种方法,但提出了寻找另一种解决方案的问题,以避免在构建代理上安装整个 VS 2019 Enterprise。
它包含所有需要的程序集,代码覆盖率只是企业版的一部分。
我更喜欢该解决方案,因为不需要修改构建管道。否则,必须修改所有现有构建管道以匹配其他建议的解决方案。
如果可以接受编辑现有管道,下面列出了其他建议的解决方案。
所有建议的解决方案:
- 使用
Coverlet
(Coverlet.MsBuild) by installing it via NuGet into test projects and importing its results (maybe in combination use withReportGenerator
- 正在安装
Test Agent/Controller
并在构建管道的 MSTest 任务中引用其vstest.console.exe
- 将所需的二进制文件复制到构建代理上的相关目录
感谢您的建议和投入的时间。
使用 Visual Studio Test Platform Installer task 对我有用。
只需确保将 vsTestVersion
更改为 toolsInstaller
- task: VisualStudioTestPlatformInstaller@1
inputs:
packageFeedSelector: 'nugetOrg'
versionSelector: 'specificVersion'
testPlatformVersion: '16.11.0'
- task: VSTest@2
inputs:
...
vsTestVersion: 'toolsInstaller'
codeCoverageEnabled: true
(测试版本 16.11.0,3 小时前发布,不确定之前是否可用)
我有一个缺点,以前我可以使用一个 variable/parameter 来设置 VSTest 和 VSBuild 版本,因为它们都有使用相同格式(15.0、16.0、最新)的版本参数,但工具安装程序需要一个特定的版本,所以如何保持同步并不简单,但也不清楚我们是否需要,也许不需要。