SonarQube not generating report - The main branch has no lines of code

Hi,
I am using Standalone scanning option in Prepare analysis on SonarQube task in Azure DevOps CI for .Net project.
I am using Self-hosted agent.
There are some constraint of using MSbuild scanning so we selected Standalone as a scan option.
When I run the CI pipeline and after successfully scanning the code and publishing the report if I check the report on SonarQube Dashboard I get the message “The main branch has no lines of code”.
If i check the Logs for Run code Analysis each and every files are getting scanned and indexed properly than to i am getting the above error.

Hi @chirag.ashiyani ,

Welcome to SonarSource Community! :sonarsource:

Please add sonar.verbose=true to the extraProperties key in SonarQubePrepare task with Azure pipelines yaml and share the logs here.

If you want a quick solution that may not necessarily pertain to your problem, you can try this solution by setting sonar.scm.exclusions.disabled=true, but you should check your logs first.

Joe

Summary

logs.txt (69.7 KB)

Please find attached Log.
I tried adding sonar.scm.exclusions.disabled=true than too the same error on Sonarqube Dashboard.

@chirag.ashiyani : Sorry, I reread your opening post. You should not use “Standalone” as scan option for your MSBuild or .NET project. You need to use MSBuild for scanner mode. What constraint are you encountering? Can you show the original set of logs with your issue? Please add sonar.verbose=true to SonarQubePrepare task to get debug logs. Please also show your azure pipeline yaml.

Hi,

I am getting a strange behavior in SonarQube.
If I run the SonarQube using azure devops CI on my Feature branch it will give pass and have some result on dashboard.
Same if i run on the master branch i am getting The main branch has no lines of code.
Please find screen shot.

Azure DevOps CI pipeline:
CI-Pipeline.txt (8.5 KB)

Logs:
logRunCodeAnalysis.txt (638.2 KB)

Hi @chirag.ashiyani ,

I see files indexed, but none of them were scanned for C# because you are using the standalone scanning option:

2021-04-23T12:13:06.1168921Z [command]C:\Windows\system32\cmd.exe /D /S /C "C:\agent\vsts-agent-win-x64-2.183.1\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\4.19.0\sonar-scanner\bin\sonar-scanner.bat -X"
...
2021-04-23T12:13:20.6746871Z 00:13:20.439 INFO: 1985 files indexed
...
2021-04-23T12:13:32.4979274Z 00:13:31.492 INFO: Sensor C# [csharp]
2021-04-23T12:13:32.4980002Z 00:13:31.492 INFO: Sensor C# [csharp] (done) | time=0ms

You cannot analyze C# files with standalone scanner. Please use the MSBuild scanner within the SonarrQubePrepare task. Here’s an example:

trigger:
- main

pool:
  vmImage: 'macOS-latest'

steps:
- task: SonarQubePrepare@4
  inputs:
    SonarQube: 'sq-service-connection85'
    scannerMode: 'MSBuild'
    projectKey: 'blorc-openidconnect'
    projectName: 'blorc-openidconnect'
    extraProperties: |
      sonar.verbose=true
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: 'src/Blorc.OpenIdConnect.sln'
    arguments: /nowarn:S4834,S4136,S125,S1135,S1128,S3903
- task: SonarQubeAnalyze@4
- task: SonarQubePublish@4
  inputs:
    pollingTimeoutSec: '300'

Hi @Joe,
I am facing a similar issue. A month ago when I added SonarQube to the microsoft azure build pipeline with standalone scanning option, it was working fine. However now all my .Net projects show “The main branch has no lines of code” in sonarqube server.
I followed the steps you have mentioned above and tried to work around with MSBuild Scanner.
But it shows following error:
The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects. Possible causes: 1. The project has not been built - the project must be built in between the begin and end steps 2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported. 3. The begin, build and end steps have not all been launched from the same folder 4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)

MSBuild and DotNet versions are up-to-date.

Your help will be most appreciated. Thank you.

Hi @kshah ,

Please create a new thread so that we can better assist you. Appending a question to a thread that may have a different context can be difficult to follow. This will also allow us to focus on your question in a new thread.

To answer you briefly, please open a new thread and provide the following information:

  • What is the version of the Scanner for .NET (MSBuild) that you are using?
  • What version of MSBuild are you using?
  • Please verify each of the four things you see in the error output
  • Please attach your Azure build pipeline yaml

And we’ll need the logs:

  • Please give us the verbose output of the scanner commands (please run SonarScanner.MSBuild.exe begin /k:“MyProject” /d:sonar.verbose=true as the begin step, and please attach the output of the BEGIN and END steps)
    Similar for SonarQubePrepare :
          extraProperties: |
            sonar.verbose=true