Azure Devops Pipeline SonarCloud not submitting code for .NET Core builds?

We are using Azure Devops Build pipeline to submit code for analysis to SonarCloud.

This works out of the box for building our .NET Framework solutions, but I currently cannot see it working correctly for .NET Core.

We have the following azure pipline config:

  • task: SonarCloudPrepare@1
    displayName: “Prepare SonarCloud”
    inputs:
    SonarCloud: ‘SonarCloudName’
    organization: ‘OrgName’
    scannerMode: ‘MSBuild’
    projectKey: ‘(projectName)' projectName: '(projectName)’
    projectVersion: ‘$(Build.BuildNumber)’

  • task: DotNetCoreCLI@2
    inputs:
    arguments: --no-restore --configuration (BuildConfiguration) --output (Build.ArtifactStagingDirectory)
    projects: $(solutionSubDirectory)/Example.csproj
    command: ‘publish’
    publishWebProjects: false
    zipAfterPublish: true

  • task: VSTest@2
    displayName: “Run Unit Tests”
    inputs:
    testSelector: ‘testAssemblies’
    testAssemblyVer2: |
    ExamplePath\UnitTests.dll
    searchFolder: ‘$(System.DefaultWorkingDirectory)’

  • task: SonarCloudAnalyze@1

The pipeline successfully passes, and we can see the branch has run within SonarCloud, and a quality gate assigned, however, there are no issues. When you browse to the “Code” tab in SonarCloud it’s empty (to me, this suggests it’s not successfully uploaded the files correctly?)

Output for the “PrepareSonarCloud” step:
SonarScanner for MSBuild 4.7.1
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories…
12:33:27.015 Updating build integration targets…
12:33:27.031 Fetching analysis configuration settings…
12:33:29.353 Provisioning analyzer assemblies for cs…
12:33:29.353 Installing required Roslyn analyzers…
12:33:31.06 Provisioning analyzer assemblies for vbnet…
12:33:31.06 Installing required Roslyn analyzers…
12:33:31.091 Pre-processing succeeded.
##[section]Finishing: Prepare SonarCloud

The SonarCloudAnalyze stage output:
SonarScanner for MSBuild 4.7.1
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
12:34:07.271 Fetching code coverage report information from TFS…
12:34:07.271 Attempting to locate a test results (.trx) file…
12:34:07.287 Looking for TRX files in: d:\a\1\TestResults
12:34:07.287 No test results files found
12:34:07.287 Did not find any binary coverage files in the expected location.
12:34:07.287 Falling back on locating coverage files in the agent temp directory.
12:34:07.287 Searching for coverage files in d:\a_temp
12:34:07.287 No coverage files found in the agent temp directory.

Calling the SonarQube Scanner…
INFO: Project root configuration file: d:\a\1.sonarqube\out\sonar-project.properties
INFO: SonarQube Scanner 4.1.0.1829
INFO: Java 1.8.0_222 Azul Systems, Inc. (64-bit)
INFO: Windows Server 2019 10.0 amd64
INFO: User cache: C:\Users\VssAdministrator.sonar\cache
INFO: SonarQube server 8.0.0


INFO: Indexing files…


INFO: Base dir: D:\a\1\s
INFO: 85 files indexed
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for cs: Sonar way

So to me it looks like it is finding and processing it correctly, but I’m not seeing the output in SonarCloud as I would expect?

Any ideas on what I may have missed would be greatly appreciated :slight_smile:

NB: I have already had to add a ProjectGuid to my .csproj files in order to get to this “successfully” passing stage.

Thank you in advance for anyones time!

Update:

I’ve tried it on another .net framework project, and it’s the same boat. The build pipeline successfully runs the SonarCloud steps, and SonarCloud can see it… but it’s all green, with no code

I’ve noticed that on the build which is working, I have the following lines in the log:
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=62ms
INFO: SCM provider for this project is: git
INFO: 43 files to be analyzed
INFO: 43/43 files analyzed
INFO: 1 file had no CPD blocks
INFO: Calculating CPD for 36 files
INFO: CPD calculation finished
INFO: SCM writing changed lines
INFO: SCM writing changed lines (done) | time=689ms
INFO: Analysis report generated in 814ms, dir size=539 KB
INFO: Analysis report compressed in 141ms, zip size=196 KB
INFO: Analysis report uploaded in 407ms

But on the one which isn’t working, it has the following:
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=59ms
INFO: 18 files had no CPD blocks
INFO: Calculating CPD for 61 files
INFO: CPD calculation finished
INFO: SCM writing changed lines
INFO: SCM writing changed lines (done) | time=0ms
INFO: Analysis report generated in 110ms, dir size=197 KB
INFO: Analysis report compressed in 78ms, zip size=86 KB
INFO: Analysis report uploaded in 266ms

Feeling sheepish now…

The one that was working, was an Azure Devops build which I’d setup to trigger on the branch.
The one that wasn’t working, was submitted as part of the PR. Because I didn’t have a master branch built yet, that’s why everything was all green as there was nothing to compare it against.

Upon merging the PR, and it actually building the branch, the code is now appearing in SonarCloud :smiley:

3 Likes