Sonarcloud on pull request doesn't analyse my new lines of code

Hi Team,

Our code has been developed in dotnet version 6 in azure repo. We have integrated sonarcloud in our azure devops pipeline to analyse and build the code.

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore Virtue.API'
  inputs:
    command: 'restore'
    projects: '$(Build.SourcesDirectory)/Virtue/Virtue.API/Virtue.API.csproj'
    includeNuGetOrg: true
    noCache: true

- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'SonarCloud Service Connection'
    organization: '<organization>'
    scannerMode: 'MSBuild'
    projectKey: '<projectKey>'
    projectName: 'projectName'
    extraProperties: |
      sonar.projectBaseDir=$(Build.SourcesDirectory)
      sonar.exclusions=**/README.md,**/obj/**,**/*.dll
      sonar.inclusions=**/*.csproj
      sonar.cs.vscoveragexml.reportsPaths=$(Build.SourcesDirectory)/coverage.xml
      sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/coverage.coverlet.xml
      sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
      sonar.pullrequest.key=$(System.PullRequest.PullRequestId)
      sonar.pullrequest.branch=$(System.PullRequest.SourceBranch)
      sonar.pullrequest.base=$(System.PullRequest.TargetBranch)


- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: 'Install reportgenerator-globaltool'
  inputs:
    command: custom
    custom: 'tool'
    arguments: 'install dotnet-reportgenerator-globaltool --tool-path $(Build.SourcesDirectory)/tools --verbosity detailed'

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

- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: '$(Build.SourcesDirectory)/coverage.coverlet.xml'
    reportDirectory: '$(Build.SourcesDirectory)/coverage/'

- script: |
    dotnet tool install -g dotnet-reportgenerator-globaltool
    reportgenerator -reports:$(Build.SourcesDirectory)\coverage.coverlet.xml -targetdir:$(Build.SourcesDirectory)\CoverageReport -reporttypes:"HtmlInline;Cobertura"
  displayName: 'Generate Coverage Report'
  
- task: PublishTestResults@2
  displayName: "Publish Test Results"
  inputs:
    testResultsFormat: VSTest
    testResultsFiles: "$(Build.SourcesDirectory)/**.*trx"
    mergeTestResults: true
    condition: succeededOrFailed()

- task: SonarCloudAnalyze@1
  inputs:
    sonar.analysis.level: 'DOTNET'

- task: SonarCloudPublish@1
  inputs:
    pollingTimeoutSec: '300'

We are using yaml file for building the code in pipeline.

URL is SonarCloud

It says code analysed but zero new lines on pull request every time I run the pipeline.

In azure devops, it says coverage is not configured yet.

Please help us to fix this issue ASAP.

Thanks in advance.

Hey there.

This is pretty suspicious, as you’re telling the scanner to only include .csproj files (and no .NET files). Try removing it?

Also, you have a lot of parameters you don’t need.

None of these are needed (except maybe your coverage parameters, if you’ve configured them correctly)

sonar.analysis.level doesn’t exist.

Hi Colin,

Thank you for your reply. I could fix the issue based on your inputs. Thank you. You can close this case