.net core OpenCover未上载到Azure Devops中

.net core OpenCover未上载到Azure Devops中,.net-core,azure-devops,msbuild,sonarqube,sonarcloud,.net Core,Azure Devops,Msbuild,Sonarqube,Sonarcloud,我想把我的项目挂在云上。我使用Azure Devops Yaml管道构建并启动测试。下面是正在发生的事情的摘要 首先,我有一个准备分析任务: - task: SonarCloudPrepare@1 displayName: 'Prepare analysis on Sonarcloud' inputs: SonarCloud: 'Sonarcloud' organization: ***redacted*** scannerMode: 'M

我想把我的项目挂在云上。我使用Azure Devops Yaml管道构建并启动测试。下面是正在发生的事情的摘要

首先,我有一个准备分析任务:

  - task: SonarCloudPrepare@1
    displayName: 'Prepare analysis on Sonarcloud'
    inputs:
      SonarCloud: 'Sonarcloud'
      organization: ***redacted***
      scannerMode: 'MSBuild'
      projectKey: ***redacted***
      projectName: ***redacted***
      extraProperties: |
        sonar.exclusions=**/obj/**,**/*.dll
        sonar.branch.name=$(Build.SourceBranchName)
        sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
        sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
然后我建立了这个项目,这里一切都很好。 然后启动测试,并使用报表生成器为我的azure管道创建html报表:

  - task: DotNetCoreCLI@2
    displayName: dotnet test
    inputs:
      command: test
      arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx'
      projects: 'Tests/**/*.csproj'
      nobuild: true

  - script: |
      dotnet tool install -g dotnet-reportgenerator-globaltool
      reportgenerator "-reports:$(Build.SourcesDirectory)/**/coverage.opencover.xml" "-targetdir:$(Build.SourcesDirectory)/CodeCoverage" "-reporttypes:HtmlInline_AzurePipelines;Cobertura"
    displayName: Create Code coverage report

  - task: PublishCodeCoverageResults@1
    displayName: 'Publish code coverage'
    inputs:
      codeCoverageTool: Cobertura
      summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml'
      reportDirectory: '$(Build.SourcesDirectory)/CodeCoverage'
在这里,一切都很好,测试运行,计算覆盖率,生成报告

然后我安装typescript(用于声纳分析)并运行代码分析:

  - script: |
      cd $(Build.SourcesDirectory)/Src/***ProjectDir***
      npm install typescript
    displayName: 'Install typescript for sonar analysis'
  - task: SonarCloudAnalyze@1
    displayName: 'Run code analysis'
    continueOnError: false
  - task: SonarCloudPublish@1
    displayName: 'Publish code analysis'
    continueOnError: false
    inputs:
      pollingTimeoutSec: '300'
sonar分析会找到trx文件,但不会找到opencover覆盖率报告,即使路径在“准备分析”任务的sonar.cs.opencover.reportsPaths参数中提供

以下是日志:

D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.10.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 4.8
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
17:31:43.118  Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders...
17:31:43.197  Did not find any binary coverage files in the expected location.
17:31:43.197  Falling back on locating coverage files in the agent temp directory.
17:31:43.197  Searching for coverage files in D:\a\_temp
17:31:43.243  No coverage files found in the agent temp directory.

分析已正确上传到sonarcloud,但覆盖率显示为0%…

好的,我的坏消息,覆盖率事实上已正确报告

罪魁祸首是sonar.branch.name=$(Build.SourceBranchName) 我在第一次运行构建时没有这个选项,覆盖率不起作用,并且报告是完整的分支名称:folder/branch。 然后我将其与其他coverage参数一起添加,该参数将剥离分支的文件夹,因此具有coverage的新报告位于分支中(不包含文件夹)

然后我刷新了报告,当然没有更新


谢谢大家。

您使用的是自主机还是主机代理?
。/coverage.opencover.xml
是否包含您期望的覆盖率数据?你能在你的构建日志中看到生成的这个文件吗?我正在使用self主机,正确生成了coverage.opencover.xml文件,我已经在reportgenerator任务中使用了它。我也可以在日志中看到它。只是声纳不能探测到它。。。