Scanning C# project using SonarQube on Mac OS

I am using below commands which are suggested in the official documentation for analyzing c# or .NET projects and i guess some of the options are deprecated. (/t:Rebuild) . Can you please suggest me current valid commands to scan .sln project or link for the information on updated information regarding usage of the commands.

  • SonarScanner.MSBuild.exe begin /k: "project-key"

  • MSBuild.exe <path to solution.sln> /t:Rebuild

  • SonarScanner.MSBuild.exe end

When I try to use Rebuild option:

MANOJs-MacBook-Air:UI_Testing2 manojdeshpande$ mono /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/MSBuild.SonarQube.Runner.exe /t:Rebuild

WARNING: ------------------------------------------------------------------------

This executable is deprecated and may be removed in next major version of the SonarScanner for MSBuild. Please use 'SonarScanner.MSBuild.exe' instead.

------------------------------------------------------------------------

SonarScanner for MSBuild 4.5

Using the .NET Framework version of the Scanner for MSBuild

Default properties file was found at /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarQube.Analysis.xml

Loading analysis properties from /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarQube.Analysis.xml

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:23:39.463  05:23:39.454  Unrecognized command line argument: /t:Rebuild

05:23:39.464  05:23:39.462  A required argument is missing: /key:[SonarQube project key]

05:23:39.464  Expecting at least the following command line argument:

- SonarQube project key

When connecting to a SonarQube server earlier than version 6.1, the following command line arguments are also required:

- SonarQube project name

- SonarQube project version

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.

05:23:39.464  Pre-processing failed. Exit code: 1

I get some other error with authentication problems. Any work around this.

MANOJs-MacBook-Air:UI_Testing2 manojdeshpande$ mono /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarScanner.MSBuild.exe begin /k:"Xamarin" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="token1"

SonarScanner for MSBuild 4.5

Using the .NET Framework version of the Scanner for MSBuild

Default properties file was found at /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarQube.Analysis.xml

Loading analysis properties from /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarQube.Analysis.xml

Pre-processing started.

Preparing working directories...

05:18:52.798  Updating build integration targets...

05:18:52.833  Fetching analysis configuration settings...

05:18:52.94  Failed to request and parse 'http://localhost:9000/api/settings/values?component=Xamarin': The remote server returned an error: (401) .

05:18:52.94  Could not authorize while connecting to the SonarQube server. Check your credentials and try again.

05:18:52.941  Pre-processing failed. Exit code: 1

Hi,

In the first example, it looks as if the begin step was not actually executed. Are you sure you did run it first, and that you were in the correct directory? (You should be in the same directory for all 3 commands.)

In the second example, it looks as if the token is not valid. Are you sure it’s valid? As a sanity check, I recommend to create a new token and try again with that.

Cheers,
Janos

2 Likes

Hi.

In the first example you executed the command MSBuild.SonarQube.Runner.exe /t:Rebuild. Note that it says MSBuild.SonarQube.Runner.exe but should be msbuild.exe.

And in the second example your command line shows /d:sonar.login="token1". I don’t know if you changed the token on purpose in the example, but it looks like that you are passing the name of the token, not the token itself. It should be something like /d:sonar.login=aed81568da1a6ccba3271983864f742be5bec017 (with a real token generated by SonarQube).

3 Likes

Thank you for replies . I will try out the things which are mentioned in the comments.

Regards,
Manoj