Sonar Scan ignores code

So we are integrating the Sonar scan for our .NET codebase in azure repos , and we established a pipeline that it scans the code and publishes the results to the sonar dashboard .

However , scan results are not visible . In the sonar dashboard it shows the .cs files but does not scan them .

Please advise how to fix this ?

Note : We are using sonar Comunnity edition for this .

Hi,

Welcome to the community!

Could you elaborate on this? It’s not clear to me what is/is not happening.

 
Ann

Hi Ann ,

Below is the screen shot

So this is what we see in the dashboard as of now .
However in the code section we do see the files ,

So please advise how to fix this .
Thanks

Hi,

I wonder if analysis thinks your code is all test files. That would explain why no Lines of Code are detected (because they’re all seen as Lines of Tests).

You can read more here.

 
HTH,
Ann

Hi Ann ,

I tried by adding the

<PropertyGroup>
  <!-- Project is not a test project -->
  <SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>

in the csproj files in the codeas suggested in the articleyou shared but still the scan doesnt give any results .

Below is my pipeline for sonar scan

trigger:

  • main

pool:
name: vmsscicdsonar

variables:
solution: ‘*.sln’
buildPlatform: ‘Any CPU’
buildConfiguration: ‘Release’

steps:

  • task: CmdLine@2
    inputs:
    script: |
    #echo
    #!/bin/sh
    echo “Updating packages …”
    sudo apt-get update -y
    sudo apt-get install openjdk-11-jdk -y

  • task: SonarQubePrepare@5
    inputs:
    SonarQube: ‘sonar-el-backend’
    scannerMode: ‘CLI’
    configMode: ‘manual’
    cliProjectKey: 'E88888_xyz’
    cliProjectName: 'E
    * ’
    cliSources: ‘.’

  • task: DotNetCoreCLI@2
    inputs:
    command: ‘build’

  • task: SonarQubeAnalyze@5

  • task: SonarQubePublish@5
    inputs:
    pollingTimeoutSec: ‘300’

Please advise how to proceed further .
Thanks

Hi,

Can you share your logs, starting from the begin step?

 
Thx,
Ann

sharing the log with . please advise further .

sonarlog2.txt (109.0 KB)

thanks

Hi,

Here’s the problem:

2022-08-23T12:47:43.1190472Z WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html

You need to be using SonarScanner for .NET.

 
HTH,
Ann