Forum General

Source Code Analysis For Xamarin Project With SonarQube On Mac.

YogeswaranSivagurunathanYogeswaranSivagurunathan USMember ✭✭
edited December 2017 in General

Hi All,

Please find the below steps to implement sonarqube analysis for your Xamarin Project .

Requirements & Installation Steps :

1. MSBuild : MSbuild will be installed along with Mono already in your machine to verify, Please execute the below command in terminal
        * which msbuild
        * /Library/Frameworks/Mono.framework/Versions/Current/Commands/msbuild

2. Install Brew (You might have it already).
        * ruby -e "$(curl -fsSL"
        * To Check installation Open Terminal and Run "brew update"

3. Install Sonar : 
        * brew install sonar
        * brew install sonar-scanner

3. Run Sonar In Terminal:
        "Sonar Console" :smile:  

4. Login To Sonar In Local Machine:
        Open Browser and enter "http://localhost:9000"
        Login as admin, Password- admin

5. MSbuild for SonarQube : 
        * As of today, the latest version 3.0.2 was not support to Mac OS,  Killed my days
        * The SonarQube version should be > 4.0 +, ********In order to run on NON WINDOW OS Platform. ******** Found the answer in the below link

        * The latest release and download the plugin from - > [Edited later]
        * Have it in your preferred location.

    6. SonarC#.
        * One more Compatibility issue, The sonarQube 6.7 has the sonarC# Plugin 6.6 in administration -> marketplace, which was having issue in scanning C# code from mac. (Killed My Day Again)

        * If the version was updated by the time you read this, Please use that. You can find the official release version in.

        * SonarC# Plugin Download

        * Add SonarC# Plugin: 6.7 (This can be added manually to the Sonar Plugin folder)
                              * Open in finder /usr/local/Cellar/sonarqube/6.7/libexec/extensions/plugins
              * Paste the plugin
              * Restart sonar in terminal -> sonar restart

7. Create a Login Token In Sonar.
        * Go to sonar portal in local machine -> http://localhost:9000/
        * Login
        * Go to administration -> Security -> create new token-> Copy the token.

8. Analyse Source Code.
        * Go the source code root folder, the folder that has the project file that you want to build.
        * Run the below commands

        1. mono /<PATH TO THE MSBUILD_FOR_SONAR_LOCATION>/sonar-scanner-msbuild- begin /k:"COM.YOGI.AWESOME.APP" /n:"APP NAME" /v:"1.0" /d:sonar.login="TOKEN THAT YOU HAVE COPIED IN STEP 8"
                    2. MSbuild /t:rebuild
        3. mono /<PATH TO THE MSBUILD_FOR_SONAR_LOCATION>//sonar-scanner-msbuild- end 

     9. Once Success You can find the report in Sonar.
10. Login to SonarQube as in Step  4. Report should be available



  • I followed your setup steps but still SonarQube does not detect any code issues.

  • Could you please share the error that you are getting, that would be easy to analyze the cause.

  • Actually I get no error but two warnings. I described my problem with more details here:

  • I always get below error after appending the PATH. How to resolve this issue, i am getting this error in my mac OS

    MANOJs-MacBook-Air:sonar-scanner-msbuild- manojdeshpande$ echo $PATH
    MANOJs-MacBook-Air:sonar-scanner-msbuild- manojdeshpande$ export PATH=$PATH:/Users/manojdeshpande/Downloads/sonar-scanner-msbuild-
    MANOJs-MacBook-Air:sonar-scanner-msbuild- manojdeshpande$ SonarScanner.MSBuild.exe
    -bash: /Users/manojdeshpande/Downloads/sonar-scanner-msbuild- cannot execute binary file

  • ArunGupta.7607ArunGupta.7607 USMember ✭✭
    edited February 2019

    When i execute the last command, i get below error:
    mono /MSBuild.SonarQube.Runner.exe end /d:sonar.login="token"

    ERROR: Error during SonarQube Scanner execution
    ERROR: Line 736 is out of range for file /.cs. File has 735 lines.
    The SonarQube Scanner did not complete successfully
    14:18:57.767 Post-processing failed. Exit code: 1

    Can you help on this.

    Below are the version details:
    Downloaded SonarScanner for MSBuild from link

Sign In or Register to comment.