Sonarqube is an open platform for managing code quality, omitting the installation process and below describes how to use Sonarqube to scan C # code.
Prerequisite: Download Sonarqube Scanner for MSBuild. Https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild.
Because you are scanning a. NET core project, download the. NET core version and unzip it to a folder:
Modify SonarQube.Analysis.xml, modify sonar's service address, and login username and password
Open the cmd window and go to the source directory by command, run Sonnar Sacnner, altogether three steps:
1.dotnet <path to sonarscanner.msbuild.dll> begin
Parameter description:
/key (abbreviated K): Projectkey is the unique code for the project, and a project needs to have a separate projectkey
/name (abbreviated N): ProjectName is the name of the project
/version (abbreviated V): Projectversion is the version of the project
The complete command is as follows:
Dotnet "D:\sonar_dotnetcore\SonarScanner.MSBuild.dll" begin/k: "Netcoresonardemo"/name: "Netcoresonardemo"/version : "1.0"
Pre-processing succeeded The first step is successful, this will generate a. sonarqube folder in the project root directory,
2.dotnet Build
3.dotnet <path to sonarscanner.msbuild.dll> end
Error Pull! The reason is that we need to add a project GUID to the item, open the project, edit the Csproj,
Execute dotnet build,dotnet <path to sonarscanner.msbuild.dll> end, upload the analysis results to sonar successfully
At this point, the simple sonar analysis. NET core code is complete and the next step is to consider integrating Gitlab CI
Analyzing. NET core application with SonarQube Scanner for MSBuild