Azure DevOps 2019 Server 执行代码覆盖率测试失败

ChW*_*ChW 4 c# msbuild automated-tests code-coverage azure-devops

现在的情况:

为了使我们的Azure DevOps 2019 服务器(代理)能够构建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 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
Run Code Online (Sandbox Code Playgroud)

所有测试均已成功执行,但任务失败并显示以下消息:

##[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.
Run Code Online (Sandbox Code Playgroud)

检查整个日志后,我发现以下消息:

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.
Run Code Online (Sandbox Code Playgroud)

...以及下面几行:

 ---> 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).
Run Code Online (Sandbox Code Playgroud)

问题

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

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

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

ChW*_*ChW 5

应用解决方案

好吧,经过大量研究和阅读最佳实践后,最实用且最有针对性的解决方案是Visual Studio 2019 Enterprisebuild agent. 这是我的第一种方法,但提出了寻找另一种解决方案的问题,以避免在构建代理上安装整个 VS 2019 Enterprise。

它包含所有需要的程序集,并且代码覆盖率仅是企业版的一部分。

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

所有建议的解决方案:

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

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