Jenkins DotNet SonarScanner

  • Which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube 9.4 (build 54424)
    SonarQube Scanner for Jenkins - 2.14

  • What are you trying to achieve
    Unable to complete initial scanning of a Unity3D C# repository. Receiving errors attempting to execute the scanner

  • What have you tried so far to achieve this

  1. Tutorial for Linux + .NET Core which says to create a
node {
  stage('SCM') {
    checkout scm
  stage('SonarQube Analysis') {
    def scannerHome = tool 'SonarScanner for MSBuild'
    withSonarQubeEnv() {
      bat "dotnet ${scannerHome}\\SonarScanner.MSBuild.dll begin /k:\"<PROJECT_KEY>\""
      bat "dotnet build"
      bat "dotnet ${scannerHome}\\SonarScanner.MSBuild.dll end"

I’m unable to use invoke a DLL, as a DLL file was not installed by the Jenkins plugin.

+ ls /var/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScanner_for_MSBuild

I receive the following error:

+ /usr/local/share/dotnet/dotnet /var/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScanner_for_MSBuildSonarScanner.MSBuild.dll begin /k:<PROJECT_KEY>
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET program, but dotnet-/var/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScanner_for_MSBuildSonarScanner.MSBuild.dll does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

Attempting to execute the exe results in the following error:

+ /var/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScanner_for_MSBuild/SonarScanner.MSBuild.exe begin /k:<PROJECT_KEY>
/var/jenkins/workspace/cgs-sonarqube_main@tmp/durable-4eaca1c9/ line 1: /var/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScanner_for_MSBuild/SonarScanner.MSBuild.exe: cannot execute binary file

Hi Joshua, welcome to the community :slight_smile:

It’s been a couple of weeks since you posted, are you still having an issue with getting this running? We don’t have a lot of experience analyzing Unity projects and I’d be really interested to hear about your experiences. If you are still having this issue let me know and I will try and offer some suggestions.



@Tom_Howlett - Thanks for following up! I am still having issues getting this setup running. I can’t seem to figure out how to resolve the fact that the plugin installed an exe instead of a dll on a Mac.
I feel like there is a very simple step that I have either missed or done incorrectly, but I can’t seem to figure it out.

Hi Joshua

I think you may have a windows only version of the scanner installed. In the tutorial in step 3 it says:

Under Install from GitHub select the corresponding .NET Core scanner required for you project.

Depending on the version of .NET installed on the agent you need to select the correct scanner. I think you currently have the .NET Framework 4.6 Version of the scanner selected that is Windows only.

Hope that helps, let me know how you get on


@Tom_Howlett - After some discussion with our DevOps group, it looks like we had installed the incorrect SonarScanner.

Been doing a bit more work on trying to get this setup, and am running into a few more issues. Would appreciate any additional guidance.

We now have “SonarScanner for MSBuild - - .NET 5.0” installed. I am able to get further in the process.

It appears that Unity is currently on .NETFramework 4.7.1 for the .csproj files. I receive this error:
/usr/local/share/dotnet/sdk/5.0.201/Microsoft.Common.CurrentVersion.targets(1216,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at

We are doing some of our own digging to work out how to install these developer packs, but will take any guidance you have.


@Tom_Howlett - Here’s another attempt we’ve made.

Using SonarScanner .NET FWK 4.6 …

sh "<PATH_TO_MONO>/mono ${scannerHome}/SonarScanner.MSBuild.exe begin /k:\"<PROJECT_ID>\" /<HOST_URL> /d:sonar.login=<ACCESS_TOKEN>"
sh "<PATH_TO_MONO>/mono ${scannerHome}/SonarScanner.MSBuild.exe <PATH_TO_SLN> /t:Rebuild"
sh "<PATH_TO_MONO>/mono ${scannerHome}/SonarScanner.MSBuild.exe end"

Receive the following error:

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...
13:49:49.859  13:49:49.812  Unrecognized command line argument: <PATH_TO_SLN>
13:49:49.859  13:49:49.847  Unrecognized command line argument: /t:Rebuild
13:49:49.859  Expecting at least the following command line argument:
- SonarQube/SonarCloud project key
The full path to a settings file can also be supplied. If it is not supplied, the exe will attempt to locate a default settings file in the same directory as the SonarQube Scanner for MSBuild.
Use '/?' or '/h' to see the help message.
13:49:49.86  Pre-processing failed. Exit code: 1

@Tom_Howlett - One step further. Realized I was using SonarScanner.MSBuild.exe and not the Mono msbuild. Dumb Mistake.

I am now onto dealing with Unity needing to handle the sln and csproj files. Will report back when I have determined a solution

1 Like