.net core Azure Devops+;床罩+;SonarQube显示0%

.net core Azure Devops+;床罩+;SonarQube显示0%,.net-core,azure-devops,sonarqube,code-coverage,azure-pipelines,.net Core,Azure Devops,Sonarqube,Code Coverage,Azure Pipelines,早上好 很抱歉打扰你,我有个问题,没有线索 我在Azure DevOps上有一个管道,当我使用命令“dotnet test”时,我使用coverlet生成代码覆盖率报告 事实上,报告编写得很好 首先,在“准备对SonarQube的分析”步骤中,我设置变量“sonar.cs.opencover.reportsPaths=“$(Agent.TempDirectory)/coverage.opencover.xml” 然而,在我的生活中,最终可能会有0%的代码覆盖率…我不知道该做什么或任何线索

早上好

很抱歉打扰你,我有个问题,没有线索

我在Azure DevOps上有一个管道,当我使用命令“dotnet test”时,我使用coverlet生成代码覆盖率报告

事实上,报告编写得很好

首先,在“准备对SonarQube的分析”步骤中,我设置变量“sonar.cs.opencover.reportsPaths=“$(Agent.TempDirectory)/coverage.opencover.xml”

然而,在我的生活中,最终可能会有0%的代码覆盖率…我不知道该做什么或任何线索


谢谢

我无法重现上述问题。而且很难排除故障,因为您没有共享dotnet测试任务sonarqube准备任务的配置

我创建了一个测试项目,覆盖范围已成功发布到sonarqube服务器。您可以参考下面的步骤

1、创建sonarqube服务器并配置我的projectName和projectKey(我使用azure sonarqube容器实例,查看详细信息)

2、在azure devops中配置

创建构建管道。我使用yaml管道

准备分析配置任务中,我选择使用独立扫描仪模式手动提供配置。我设置变量
sonar.cs.opencover.reportsPaths=“$(Agent.TempDirectory)/coverage.opencover.xml”

下面的屏幕截图是任务在经典ui视图中的设置

在我的dotnet测试任务中我将参数设置如下,并将覆盖率结果具体输出到
$(Agent.TempDirectory)/
文件夹

参数:'--configuration$(buildConfiguration)/p:CollectCoverage=true/p:CoverletOutput=$(Agent.TempDirectory)//p:CoverletOutputFormat=opencover'

下面是我的azure-pipelines.yml文件的完整内容


我做了很多事情最终设法使覆盖范围工作,但我认为问题在于我的解决方案中的每个.csproj中都缺少“ProjectGUID”,使项目被SonarQube扫描器忽略

同时,我还将SonarQube 6.2升级到了8.1,这可能解决了问题


我的步骤保持不变以使这项工作正常进行。

Hi@Alex Planchon您是否查看了以下步骤?如果有任何问题,请告诉我。@LeviLu MSFT我刚刚发布了我的“解决方案”,它现在正在工作:)
trigger: none

jobs:
- job: 'Tests'
  pool: 
    vmImage: windows-latest

  variables:
    buildConfiguration: 'Release'
  continueOnError: true

  steps:     
  - task: SonarQubePrepare@4
    displayName: 'Prepare analysis on SonarQube'
    inputs:
       SonarQube: sonarlevi
       scannerMode: CLI
       configMode: manual
       cliProjectKey: myproject2
       cliProjectName: myproject2
       extraProperties: |
          sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml"


  - task: DotNetCoreCLI@2
    inputs:
      command: restore
      projects: '**\*.csproj'

  - task: DotNetCoreCLI@2
    inputs:
      command: custom
      custom: tool
      arguments: install --tool-path . dotnet-reportgenerator-globaltool 
    displayName: Install ReportGenerator tool

  - task: DotNetCoreCLI@2
    displayName: Test .NET
    inputs:
      command: test
      projects: '**\*Test*.csproj'
      publishTestResults: false
      arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.TempDirectory)/ /p:CoverletOutputFormat=opencover'
    condition: succeededOrFailed()


  - task: SonarQubeAnalyze@4

    displayName: 'Run Code Analysis'

  - task: SonarQubePublish@4

    displayName: 'Publish Quality Gate Result'