Azure DevOps 2019 Server在执行覆盖代码的测试时失败

当前情况:

为使我们的 Azure DevOps 2019 Server(代理)能够构建 ASP.NET Core 3 .Net Core 3 应用程序,我们已安装{ {3}}(扩展器 Visual Studio 2019的工具)。这不是最佳实践,但是Azure DevOps 2019 Server和代理安装在同一台计算机上。

除了收集编码器的覆盖范围之外,所有其他功能均按预期工作。构建了应用程序并提供了工件。我们可以确认,发布后的所有工件都按预期工作。
就像已经提到的,除了代码覆盖范围之外,一切都很好。

要构建的应用程序是.NET Framework 4.6.2应用程序,是在代理上成功通过VS 2017 Enterprise安装VS 2019构建工具之前构建的。

为了进行测试,我们在Visual Studio Test任务之后在构建管道中将MSTest与Visual Studio build一起使用。测试任务的配置如下:

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 Studio\2019\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).

问题

有人知道这个问题可能是什么吗?
我猜想,也许我们必须安装Build Tools for Visual Studio 2019(用于Visual Studio 2019的扩展器工具),但是我不确定这是否是正确的方法。此外,我找不到任何有意义的信息,我们必须使用哪个安装包-AgentController

过去,在大多数情况下,已经完成了完整的Visual Studio Enterprise安装,以实现代理的完整功能集。但是我想要一种更简洁的方法,并且只想安装所需的软件包,并避免为构建代理使用Enterprise许可证。

我们非常欢迎想法,方法和最佳实践。 非常感谢您的帮助。

poilkjm 回答:Azure DevOps 2019 Server在执行覆盖代码的测试时失败

适用的解决方案

好吧,经过大量研究和阅读有关最佳实践的知识之后,最可行,最针对目标的解决方案是在Visual Studio 2019 Enterprise上安装build agent。这是我的第一种方法,但提出了寻找其他解决方案的问题,以避免在构建代理上安装整个VS 2019 Enterprise。

它包含所有必需的程序集,并且代码覆盖率仅是Enterprise Edition的一部分。

我更喜欢该解决方案,因为不需要修改构建管道。否则,必须修改所有现有的构建管道以匹配其他建议的解决方案。
如果可以编辑现有管道,则下面列出其他建议的解决方案。

所有建议的解决方案:

  1. 使用Coverlet并通过NuGet将其安装到测试项目中并导入其结果(可能与ReportGenerator组合使用
  2. 在构建管道的MSTest任务中安装Test Agent/Controller并引用其vstest.console.exe
  3. 将所需的二进制文件复制到构建代理上的相关目录

感谢您的建议和投入的时间。

本文链接:https://www.f2er.com/3107282.html

大家都在问