"Unrecognized option: begin"

  • which versions are you using
    SonarQube: 9.2.0
    Scanner: 4.6.2.2472
  • what are you trying to achieve
    run sonarscanner on a unity project (.net 4.7.1) with mono inside a docker container
  • what have you tried so far to achieve this
    built a docker image like this:
  1. built from unityci/editor:2020.3.1f1-android-0.15, then install mono-devel
  2. downloaded from
    https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.4.0.40033/sonar-scanner-msbuild-5.4.0.40033-net46.zip, unzip, make executable, add /sonar-scanner-4.6.2.2472/bin to PATH
    the image builts fine and everysthing works so far.

Now the following is part of a bash script which is executed by gitlab ci inside a container with that image:

sonar-scanner -X \
      -D sonar.projectKey="$SONAR_PROJECT_KEY" \
      -D sonar.host.url="$SONAR_HOST_URL" \
      -D sonar.login="$SONAR_TOKEN" \
      -D sonar.projectVersion="$CI_PIPELINE_ID" \
      -D sonar.exclusions=../Assets/**/Plugins/**/* \
      begin
msbuild ../Assembly-CSharp-Editor.csproj
msbuild ../Assembly-CSharp.csproj
sonar-scanner -D sonar.login="$SONAR_TOKEN" end

The first command fails stating

ERROR: Unrecognized option: begin
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO: -D,–define Define property
INFO: -h,–help Display help information
INFO: -v,–version Display version information
INFO: -X,–debug Produce execution debug output

It took me some time to even get the command to not fail with a -k or -v option - because these are also invalid. I cannot find any guide or tutorial regarding this weird version of the sonar-scanner, everything I see looks entirely different.
Do I have a wrong version of the scanner? Or how am I supposed to use that one?

I think my mistake was to use

/sonar-scanner-4.6.2.2472/bin/sonar-scanner

instead I have to use

mono sonar-scanner-4.6.2.2472/SonarScanner.MSBuild.exe

I was looking at the docs for sonarscanner-for-msbuild while /bin/sonar-scanner apparently is the scanner to use when there is no specific scanner for the bujild system