C# gitlab sonarscanner fails on giltab

Hi all i am running a Gitlab CI pipeline and i am trying to add my dotcover report to sonarqube. I was able to generate the report but the coverage seems to be null. On the logs of the pipeline i saw the following warning.

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 Scanner for MSBuild 4.x

My gitlab ci job is this

sonarqube_check:

  stage: code quality

  tags:

    - sandbox

  image:

    name: sonarsource/sonar-scanner-cli:latest

  variables:

    SONAR_USER_HOME: '${CI_PROJECT_DIR}/.sonar'

    GIT_DEPTH: 0 # Tells git to fetch all the branches of the project, required by the analysis task

  script:

    - export VERSION=$(cat VERSION.txt)

    - echo $VERSION

    - mv $gitlab_cert_chain /etc/ssl/certs/gitlab_cert_chain.pem

    - mv $ev_root_ca_1 /etc/ssl/certs/EatonVanceRootCA1.crt

    - export JAVA_HOME=/opt/java/openjdk

    - export SONAR_SCANNER_OPTS="-Xmx1024m"

    - sh -c 'keytool -importcert -keypass changeit -file /etc/ssl/certs/EatonVanceRootCA1.crt -keystore $JAVA_HOME/lib/security/cacerts -noprompt -storepass changeit'

    - sonar-scanner -Dsonar.qualitygate.wait=true -Dsonar.projectVersion=$VERSION

  allow_failure: true

and the sonar properties files looks like

sonar.projectKey=GiltabPOC

sonar.language=cs

sonar.sources=./

sonar.cs.dotcover.reportsPaths = ./GitlabPOC.Test/coverage/Cobertura.xml

sonar.verbose=true

thanks in advance

Hi Sherrera,

The error you’re receiving is describing a problem with your analysis approach: if your project contains C#/.NET code, then the SonarScanner for .NET and not the plain sonar-scanner must be used for analysis.

We don’t currently have an easy/explicit tooling support for analyzing .NET code on GitLab; you can refer to this earlier thread for pointers. Basically you’re going to have to either use the dotnet CLI or a Windows-based image for running this particular pipeline.

2 Likes