Managing Files In SonarQube For ASP.NET Core Application Code Analysis

Introduction

 
In my last article I have explained how to configure SonarQube to do code analysis for our existing ASP.NET Core application. I got a comment on that article regarding a file management in SonarQube while doing a code analysis, which triggered me to write this article to show how to manage files in sonarqube code analysis, so in this article I’m going to explain how to exclude the project files which are not necessary to analyze it with the help of SonarQube UI Interface.
 

Managing files in Code Analysis

 
Go to sonarqube\bin\windows-x86-64 - >and run StartSonar.
 
Once the SonarQube is up and running, you can open the dashboard in the browser using http://localhost:9000/, and login as admin.
 
By default, the username: admin password: admin
 
Let’s take our existing ASP.NET Core application which is used in my last article to do a code analysis.
 
Managing Files In SonarQube For ASP.NET Core Application Code Analysis
 
In the overview page click on Bugs, it will take you to the issues page as shown in the below figure.
 
Managing Files In SonarQube For ASP.NET Core Application Code Analysis 
 
From the above figure you can notice, there are 18 bugs in the project, which should be resolved to pass the quality gate. Meanwhile the file bootstrap.css is from bootstrap library so obviously we are not going to touch that file for further code update. Now we should remove this file from our code analysis.
 
Go to Administration -> General setting as shown in below figure.
 
Managing Files In SonarQube For ASP.NET Core Application Code Analysis 
 
In the General Setting page, go to Analysis Scope navigate to Files-> Source File Exclusion section. Provide the file path which should be excluded from the code analysis as shown in the below figure and click on save.
 
Managing Files In SonarQube For ASP.NET Core Application Code Analysis 
 
Now, let’s start the code analysis
 
Open Visual Studio command prompt, switch to project path and provide the below command:
 
SonarScanner.MSBuild.exe begin /k:"asp.net_core_demo" /d:sonar.host.url="http://localhost:9000" /d:sonar.login=" Give your project token" /v:"2020.01.15"
  
Next, we want to rebuild the project using the below command. 
  
MsBuild.exe [Project Solution file Name]/t:Rebuild /p:Configuration=Release /p:Platform="Any CPU" /p:TargetProfile=Local 
 
The final step, end SonarScanner using the below command
 
SonarScanner.MSBuild.exe end /d:sonar.login="Give your project token"
 
Once the scanning is done, go to SonarQube dashboard in browser and switch to your project, you can see the code analysis report, click on the bugs, now you can see the bugs got reduced from the number 18 to 15, which means the 3 bugs from the file bootstap.css are not in the list because this file is excluded from the analysis.
 
Managing Files In SonarQube For ASP.NET Core Application Code Analysis 
 

Summary

 
We have seen how to manage the files in Sonarqube while doing the code analysis of our ASP.NET Core application.