How to run SonarQube in a C # .NET project?

I have a C # / project. NET, which I want to scan with SonarQube (C # language).

I get a scan, but with many errors (over 200 repeated errors)

Provide an 'AssemblyVersion' attribute for this assembly. 

This message above is repeated many times and takes into account most of the SonarQube errors that I see in my report.

SonarQube Properties File

 # Comma-separated paths to directories with sources (required) #sonar.sources=controllers,services sonar.sources=. # Language sonar.language=cs sonar.visualstudio.solution=ProjectName.sln sonar.sourceEncoding=UTF-8 sonar.cobol.copy.diretories=/copy sonar.visualstudio.enable=true 

I even ran this msbuild (using MSBuild.exe Version 14, which I downloaded from https://www.microsoft.com/en-us/download/details.aspx?id=48159 ) batch file in my project

 C:\Users\pwrdbyadmin\Desktop\sonar-scanner-msbuild-3.0.2.656\SonarQube.Scanner.MSBuild.exe begin /k:"org.sonarqube:sonarqube-scanner-msbuild" /n:"ProjectName" /v:"1.0" "C:\Program Files (x86)\MSBuild\14.0\Bin\amd64\MSBuild.exe" /t:Rebuild C:\Users\pwrdbyadmin\Desktop\sonar-scanner-msbuild-3.0.2.656\SonarQube.Scanner.MSBuild.exe end 

Loaded SonarQube 6.5 and ran the following command to start the server

 C:\Users\pwrdbyadmin\Desktop\sonarqube-6.5\bin\windows-x86-32\StartSonar.bat 

Team running from project

 C:\Users\username\Desktop\sonar-scanner-3.0.3.778-windows\bin\sonar-scanner.bat 

I still cannot resolve many of the .NET errors in my project.

How can I fix these obvious C # errors that occur after running SonarQube in my project, do I need Visual Studio, do I need to create my own project in Visual Studio? What are the necessary steps to scan my project?

EDIT

The new three liners allowed the analysis to work without any error. There is not enough privilege that appears at the end. I used the latest MSBuild.exe VS 2017 in my 3 line command

 C:\Users\<UserName>\Desktop\sonar-scanner-msbuild-3.0.2.656\SonarQube.Scanner.MSBuild.exe begin /d:"sonar.host.url=http://localhost:9000" /d:"sonar.login=<login>" /d:"sonar.password=<password>" /k:"org.sonarqube:sonarqube-scanner-msbuild" /n:"<ProjectName>" /v:"1.0" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" /t:Rebuild C:\Users\<UserName>\Desktop\sonar-scanner-msbuild-3.0.2.656\SonarQube.Scanner.MSBuild.exe end /d:"sonar.login=<login>" /d:"sonar.password=<password>" 

Despite using an updated sequence of commands, I still get build version errors in my report.

Do I need to delete the project and reanalyze. In addition, I even thought that my 3-line display shows that MSBuild 15 is in use, a yellow notification appears that I am using MSBuild 12. I'm not sure why.

UPDATE: Screenshot of duplicate files / folders in code smell analysis.

enter image description here

+5
source share
1 answer

I'm not sure where the SonarQube.Properties file is used. I could not find this in my setup.

Make sure that all the projects you are viewing have a Properties folder and under that AssemblyInfo.cs, which contains the version of the assembly. The file must be included in the project. You can see this from Visual Studio.

Make sure you provide the SonarQube address and authentication information in the SonarQube.Analysis.xml file

sonar.host.url - URL of your SonarQube server sonar.login - Analytical user token with the permissions “Perform analysis”. Only required if anonymous does not have them

Create a new bat file with only these lines.

 <local path>/SonarQube.Scanner.MSBuild.exe begin /k:"<SomeProjectNameKey>" /n:"<YourProjectName>" /v:"1.0" <local path>/MSBuild.exe /t:Rebuild /tv:15.0 /p:VisualStudioVersion=15.0 <local path>/SonarQube.Scanner.MSBuild.exe end 

The bat file must be in the same folder as the projects.

Documentation link https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild

+2
source

Source: https://habr.com/ru/post/1271434/


All Articles