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 https://raw.github.com/Homebrew/homebrew/go/install)"
        * 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
            https://groups.google.com/d/msg/sonarqube/wLaU3ijlqDk/YmETdAjmAgAJ

        * The latest release and download the plugin from - > https://docs.sonarqube.org/pages/viewpage.action?pageId=6954799 [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.
            [https://docs.sonarqube.org/pages/viewpage.action?pageId=1441900]

        * SonarC# Plugin Download
            [https://github.com/SonarSource/sonar-csharp/releases/tag/6.7.0.4267]

        * 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-4.0.0.731/MSBuild.SonarQube.Runner.exe 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-4.0.0.731/MSBuild.SonarQube.Runner.exe end 

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

Thanks

Posts

  • 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:

    stackoverflow.com/questions/47890996/sonarqube-does-not-detect-c-sharp-issues-in-xamarin-project

  • 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-4.5.0.1761-net46 manojdeshpande$ echo $PATH
    /Library/Frameworks/Mono.framework/Commands/:/anaconda3/bin:/Users/manojdeshpande/miniconda3/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin
    MANOJs-MacBook-Air:sonar-scanner-msbuild-4.5.0.1761-net46 manojdeshpande$ export PATH=$PATH:/Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46
    MANOJs-MacBook-Air:sonar-scanner-msbuild-4.5.0.1761-net46 manojdeshpande$ SonarScanner.MSBuild.exe
    -bash: /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarScanner.MSBuild.exe: cannot execute binary file

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

    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.
    ERROR:
    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:
    SonarQube: 7.4.0.18908
    SonarScanner: 3.3.0.1492
    Downloaded SonarScanner for MSBuild 4.6.0.1930 from link https://docs.sonarqube.org/pages/viewpage.action?pageId=6954799

Sign In or Register to comment.