SonarQube MSBuild scanner not working on Ubuntu 18.04 LTS

Must-share information (formatted with Markdown):
I am using SonarQube v8.2 on Ubuntu 18.04 LTS

I am trying to analyse C project using the MSBuild Scanner. I have installed the MSBuild scanner and SonarQube successfully on the Ubuntu 18.04 LTS host. I have downloaded the sonar examples from the website and when I try to execute the MSBuild scanner on the project file using the following commands:

Method 1:

  1. sudo dotnet-scanner begin /k:“TEST2” /d:sonar.host.url=“http://1**...:9000" /d:sonar.login="19**********************************”
  2. sonar@ubuntu:/opt/sonarqube$ dotnet-scanner MsBuild.exe /t:Rebuild
    SonarScanner for MSBuild 4.8
    Using the .NET Core version of the Scanner for MSBuild
    WARNING: Please specify the command ‘begin’ or ‘end’ to indicate whether pre- or post-processing is required. These parameters will become mandatory in a later release.
    Pre-processing started.
    Preparing working directories…
    05:45:24.954 05:45:24.949 Unrecognized command line argument: MsBuild.exe
    05:45:24.954 05:45:24.953 Unrecognized command line argument: /t:Rebuild
    05:45:24.954 05:45:24.954 A required argument is missing: /key:[SonarQube project key]
    05:45:24.954 Expecting at least the following command line argument:
  • SonarQube project key
  1. sudo dotnet-scanner end /d:sonar.login=“1*****************************”
    SonarScanner for MSBuild 4.8
    Using the .NET Core version of the Scanner for MSBuild
    Post-processing started.
    The SonarQube 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)
    Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
    05:46:48.965 Post-processing failed. Exit code: 1

I understand the error in step 3 is because step 2 failed. I do not know why step 2 is failing and this is what I need help with.

Method 2:
I try to use mono instead why is what has been put on the instructions in the website but I get the following:
sonar@ubuntu:/opt/sonarqube$ mono SonarScanner.MSBuild.exe begin /k:“TEST2” /d:sonar.host.url=“http://1**..:9000" /d:sonar.login="1***********************************”

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly or one of its dependencies.
File name: ‘netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’
at SonarScanner.MSBuild.Program.Main (System.String args) [0x00000] in <2f287f3241ad422dac2268b604a6ee4e>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly or one of its dependencies.
File name: ‘netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’
at SonarScanner.MSBuild.Program.Main (System.String args) [0x00000] in <2f287f3241ad422dac2268b604a6ee4e>:0
sonar@ubuntu:/opt/sonarqube$ mono
Usage is: mono [options] program [program-options]

Development:
–aot[=] Compiles the assembly to native code
–debug[=] Enable debugging support, use --help-debug for details
–debugger-agent=options Enable the debugger agent
–profile[=profiler] Runs in profiling mode with the specified profiler module
–trace[=EXPR] Enable tracing, use --help-trace for details
–jitmap Output a jit method map to /tmp/perf-PID.map
–help-devel Shows more options available to developers

Runtime:
–config FILE Loads FILE as the Mono config
–verbose, -v Increases the verbosity level
–help, -h Show usage information
–version, -V Show version information
–runtime=VERSION Use the VERSION runtime, instead of autodetecting
–optimize=OPT Turns on or off a specific optimization
Use --list-opt to get a list of optimizations
–security[=mode] Turns on the unsupported security manager (off by default)
mode is one of cas, core-clr, verifiable or validil
–attach=OPTIONS Pass OPTIONS to the attach agent in the runtime.
Currently the only supported option is ‘disable’.
–llvm, --nollvm Controls whenever the runtime uses LLVM to compile code.
–gc=[sgen,boehm] Select SGen or Boehm GC (runs mono or mono-sgen)

As you can see, I have installed mono without any issues.

Can someone please help me with this issue.

Thanks

Hi @sayed

You are missusing the tool in your first step 2

You have to do it like this :

  1. dotnet-sonarscanner begin …
  2. dotnet build (and not dotnet-sonarscanner MSBuild…) as you are on Linux, you cannot invoke MSBuild.exe, use dotnet CLI instead.
  3. dotnet-sonarscanner end…

HTH,
Mickaël