首页 > 解决方案 > Azure DevOps 2019 Server 在执行具有代码覆盖率的测试时失败

问题描述

现在的情况:

为了使我们的Azure DevOps 2019 服务器(代理)能够构建ASP.NET Core 3.Net Core 3应用程序,我们在其上安装了 Visual Studio 2019 的构建工具(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

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

##[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).

问题

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

过去,大部分时间都完成了完整的 Visual Studio Enterprise 安装,以实现代理的完整功能集。但我想要一种更干净的方法,并且只想安装需要的软件包,并避免使用企业许可证作为构建代理。

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

标签: c#msbuildazure-devopsautomated-testscode-coverage

解决方案


应用解决方案

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

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

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

所有建议的解决方案:

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

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


推荐阅读