完全相同的 OpenCover 脚本在本地 运行 时成功完成,但在通过 Azure DevOps 运行 时失败

Exact same OpenCover script completes successfully when run locally, but fails when run via Azure DevOps

直到几天前,我一直在使用 OpenCover 运行 我的单元测试和输出代码覆盖率,没有失败。我有一个 powershell 脚本,我可以在本地 运行 也可以在 Azure DevOps 构建中使用它,并且没有任何问题。但是现在,OpenCover 不仅仅适用于 Azure DevOps。

我在我的 Azure DevOps 实例中将我的计算机配置为构建代理 运行作为我在本地成功 运行 OpenCover 时登录的同一用户作为服务。

$info = New-Object System.Diagnostics.ProcessStartInfo
$info.FileName = "C:\Users\devuser\.nuget\packages\opencover.6.519\tools\OpenCover.Console.exe"
$info.RedirectStandardError = $true
$info.RedirectStandardOutput = $true
$info.UseShellExecute = $false
$info.Arguments = "`
                -target:""C:\Program Files (x86)\Microsoft Visual Studio19\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"" `
                -targetargs:""C:\agent\_work\s\UnitTests\bin\Debug\UnitTests.dll"" `
                -output:""C:\agent\_work\s\opencover.xml"" `
                -filter:""+[*]*.Service.* +[*]*.Model.* +[*]*.Repository.*"" `
                -excludebyfile:*""*\*Designer.cs"" `
                -mergebyhash `
                -skipautoprops `
                -returntargetcode `
                -register:user"

$exec = New-Object System.Diagnostics.Process
$exec.StartInfo = $info
$exec.Start() | Out-Null
$exec.StandardOutput.ReadToEnd() | Out-File -FilePath "C:\agent\_work\s\log.txt"
$exec.StandardError.ReadToEnd() | Out-File -FilePath "C:\agent\_work\s\log_errors.txt"

当运行在本地运行上述脚本时,我得到了预期的结果:

Executing: C:\Program Files (x86)\Microsoft Visual Studio19\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe
Microsoft (R) Test Execution Command Line Tool Version 16.2.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
  û GetBookByBookID [636ms]
  û SelectBooksByUser [132ms]
  û SelectAllBooks [64ms]
  û GetBookIDByCoinID [70ms]
  û SelectCoinsByBook [79ms]
  û PingS3 [922ms]
  û GetCoinByCoinID [140ms]
  û SelectCoinsBySearch [66ms]
  û AddAndRemoveCoin [383ms]
  û SelectAllCoins [170ms]
  û SelectAllCoinsByBookByUser [135ms]
  û SelectOwnedCoinsByBook [128ms]
  û SelectAllMintmarks [63ms]
  û SelectAllYears [75ms]
  û SelectAllDenominations [63ms]
  û SelectAllLinkUserCoin [189ms]
  û SelectUsers [125ms]
  û GetUserNameByUserID [62ms]
  û GetUserIDByUserName [69ms]
  û SelectUsersByOwned [189ms]
  û SelectAllLinkUserBook [67ms]

Test Run Successful.
Total tests: 21
     Passed: 21
 Total time: 6.0269 Seconds
Committing...
Visited Classes 11 of 11 (100)
Visited Methods 57 of 57 (100)
Visited Points 336 of 336 (100)
Visited Branches 105 of 113 (92.92)

==== Alternative Results (includes all methods including those without corresponding source) ====
Alternative Visited Classes 11 of 11 (100)
Alternative Visited Methods 62 of 62 (100)

但是 运行通过 Azure DevOps 使用完全相同的脚本,我得到了这个:

Executing: C:\Program Files (x86)\Microsoft Visual Studio19\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe
Microsoft (R) Test Execution Command Line Tool Version 16.2.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
  √ GetBookByBookID [471ms]
  √ SelectBooksByUser [136ms]
  √ SelectAllBooks [62ms]
  √ GetBookIDByCoinID [62ms]
  √ SelectCoinsByBook [66ms]
  √ PingS3 [417ms]
  √ GetCoinByCoinID [133ms]
  √ SelectCoinsBySearch [66ms]
  √ AddAndRemoveCoin [413ms]
  √ SelectAllCoins [134ms]
  √ SelectAllCoinsByBookByUser [142ms]
  √ SelectOwnedCoinsByBook [129ms]
  √ SelectAllMintmarks [63ms]
  √ SelectAllYears [64ms]
  √ SelectAllDenominations [61ms]
  √ SelectAllLinkUserCoin [148ms]
  √ SelectUsers [134ms]
  √ GetUserNameByUserID [63ms]
  √ GetUserIDByUserName [61ms]
  √ SelectUsersByOwned [225ms]
  √ SelectAllLinkUserBook [64ms]

Test Run Successful.
Total tests: 21
     Passed: 21
 Total time: 4.8670 Seconds
Committing...
No results, this could be for a number of reasons. The most common reasons are:
    1) missing PDBs for the assemblies that match the filter please review the
    output file and refer to the Usage guide (Usage.rtf) about filters.
    2) the profiler may not be registered correctly, please refer to the Usage
    guide and the -register switch.

我已经用谷歌搜索了两个建议的原因,但我已经在使用

-register:user

很明显,pdb 在那里,因为构建配置是 Debug,它 运行 在本地如预期的那样,都在同一个用户下。

有什么建议吗?我对 Azure DevOps 上可能发生的事情感到茫然 different/missing 以及为什么在成功使用此脚本几个月后会发生这种情况...

解决方案是使用:

-register:Path32

而不是:

-register:user

参考:https://github.com/OpenCover/opencover/issues/915#issuecomment-526284026