Create .gitlab-ci.yml .net project

I was trying to analise a gitlab project in my sonarqube server, Gitlab onpremise was integrated in sonar
I created variables in my gitlab project
I created .gitlab-ci.yml with this content

sonarqube-check:
variables:
SONAR_USER_HOME: “${CI_PROJECT_DIR}/.sonar” # Defines the location of the analysis task cache
GIT_DEPTH: “0” # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: “${CI_JOB_NAME}”
paths:
- .sonar/cache
script:
- “dotnet sonarscanner begin /k:"PROJECT” /d:sonar.login="$SONAR_TOKEN" /d:"sonar.host.url=$SONAR_HOST_URL" "
- “dotnet build”
- “dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"”
allow_failure: true
only:
- master # or the name of your main branch

When I executed this command in runner server

dotnet sonarscanner begin /k:"PROJECT" /d:sonar.login="$SONAR_TOKEN\

it was succesfull

But in pipeline showed this error

$ dotnet sonarscanner begin /k:"MYPROJECT" /d:sonar.login="$SONAR_TOKEN" /d:"sonar.host.url=$SONAR_HOST_URL"
No se pudo ejecutar porque no se encontr� el comando o el archivo especificado.

Algunas de las posibles causas son :
Escribi� mal un comando dotnet integrado.
Pretend�a ejecutar un programa .NET, pero dotnet-sonarscanner no existe.
Pretend�a ejecutar una herramienta global, pero no se encontr� ning�n ejecutable con prefijo dotnet con este nombre en PATH.

Could you help me? How do you create .gitlab-ci.yml to scan your gitlab projects?

Hey there.

The tutorial in the UI suggests a YML file that looks like this:

sonarqube-check:
  image: mcr.microsoft.com/dotnet/core/sdk:latest
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
      - "apt-get update"
      - "apt-get install --yes openjdk-11-jre"
      - "dotnet tool install --global dotnet-sonarscanner"
      - "export PATH=\"$PATH:$HOME/.dotnet/tools\""
      - "dotnet sonarscanner begin /k:\"tewafsdf\" /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "
      - "dotnet build"
      - "dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
  allow_failure: true
  only:
    - merge_requests
    - master # or the name of your main branch
    - develop

So you’re missing some steps, like installing the dotnet-sonarscanner global tool.