封面报道报告导致 Microsoft.VisualStudio.Coverage.VanguardException

coverlet coverage report resulting in Microsoft.VisualStudio.Coverage.VanguardException

我正在尝试将 Cobertura 报告生成集成到我的 Azure 管道中。为此,我在我的 .Net 核心测试项目中添加了 coverlet.collector 3.0.3。下面是我用于测试的 yaml 命令 运行

- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '**/*Test/*.csproj'
    arguments: '--collect:"XPlat Code Coverage"  --settings CodeCoverage.runsettings --logger trx'
    publishTestResults: false

我使用 Reportgenerator 任务来合并和发布覆盖率报告。这一切在我的代码的一个分支(一个旧分支,我前一段时间开始在其上设置管道)中都运行良好。但是当我试图指向管道中的最新分支时,出现如下错误

Data collector 'Code Coverage' message: Data collector caught an exception of type 'Microsoft.VisualStudio.Coverage.VanguardException': 'Running event not received from CodeCoverage.exe. Check eventlogs for failure reason

我几乎检查了两个分支中的所有内容,Microsoft.Net.Test.SDK、coverlet.collector,两者的版本相同。我不确定 2 个分支之间有什么区别以及我应该在 2 个代码分支之间寻找哪些差异,这可能会导致此类问题。

下面添加了成功和失败的完整日志。

成功(使用旧分支时)

C:\windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
"C:\Program Files\dotnet\dotnet.exe" test I:\Agent-Win-R_work9\s\XXXX.Business.Test\XXXX.Business.Test.csproj "--collect:XPlat Code Coverage" --settings CodeCoverage.runsettings --logger trx
Test run for I:\Agent-Win-R_work9\s\XXXX.Business.Test\bin\Debug\netcoreapp3.1\XXXXWeb.Business.Test.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.5.0
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
Microsoft (R) Coverage Collection Tool Version 16.0.30319.3002

Copyright (c) Microsoft Corporation. All rights reserved.

Results File: I:\Agent-Win-R_work9\s\XXXX.Business.Test\TestResults\SVCGIDETFSProdBld01_MP-GIDE-522C_2021-07-01_04_18_04.trx

Attachments:
I:\Agent-Win-R_work9\s\XXXX.Business.Test\TestResultsf62864f-6c2c-4188-ac02-0dc536b464b3\coverage.cobertura.xml
I:\Agent-Win-R_work9\s\XXXX.Business.Test\TestResultsf62864f-6c2c-4188-ac02-0dc536b464b3\SVCGIDETFSProdBld01_MP-GIDE-522C_2021-07-01.04_17_58.coverage
Test Run Successful.
Total tests: 6
Passed: 6
Total time: 3.8813 Seconds

失败(指向新分支时)

C:\windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
"C:\Program Files\dotnet\dotnet.exe" test I:\Agent-Win-R_work9\s\XXXX.Test\XXXXBusiness.Test.csproj "--collect:XPlat Code Coverage" --settings CodeCoverage.runsettings --logger trx
Test run for I:\Agent-Win-R_work9\s\XXXX.Business.Test\bin\Debug\netcoreapp3.1\XXXXWeb.Business.Test.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.5.0
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
Data collector 'Code Coverage' message: Data collector caught an exception of type 'Microsoft.VisualStudio.Coverage.VanguardException': 'Running event not received from CodeCoverage.exe. Check eventlogs for failure reason.'. More details: ..
Results File: I:\Agent-Win-R_work9\s\XXXX.Business.Test\TestResults\SVCGIDETFSProdBld01_MP-GIDE-522C_2021-07-01_04_12_42.trx

Attachments:
I:\Agent-Win-R_work9\s\XXXX.Business.Test\TestResults39c24a-e17d-4d0d-9953-359388d5a940\coverage.cobertura.xml
Test Run Failed.
Total tests: 6
Passed: 6

我也遇到了这个问题线程:https://github.com/microsoft/azure-pipelines-agent/issues/2839 用户怀疑它是代理升级问题,但对我来说似乎不是这种情况,因为我能够 运行 它成功地用于一个代码分支。

如有任何建议或指导,我们将不胜感激。

当我向 Coverlet 团队提出这个问题时,我得到了他们的快速回复。他们注意到了一些我完全错过的东西。

Microsoft (R) Coverage Collection Tool Version 16.0.30319.3002

这出现在我的成功日志中,这意味着 Microsoft 代码覆盖率 运行ning 与 Coverlet 代码覆盖率并行。他们怀疑如果你同时有两个代码覆盖收集器 运行ning,我们会得到一些奇怪的错误,并且两个分支中的测试方式 运行 之间的一些时间问题会导致不同的行为。

我在 .运行settings 文件中禁用了 Microsoft 代码覆盖后,问题就得到了解决

早些时候:

 <DataCollector friendlyName="XPlat code coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      

现在

<DataCollector friendlyName="XPlat code coverage">