This project demonstrates integrating a simple .NET Console application with SonarQube for static code analysis and quality checks.
- Docker for SonarQube
- .NET SDK for building and testing
- SonarQube instance (local or cloud)
-
Clone the repo and run SonarQube with Docker Compose:
cd container-labs/labs/sonar/sonar-basic/ docker-compose up -dNOTE: The docker compose file using in this project is for Docker Desktop, if you use linux based OS, adjust the volume mount command appropriately
-
Access SonarQube at
http://localhost:9000(default credentials:admin/admin). -
Create a project in SonarQube and get the project key and token.

-
We will run a sample .NET code scan in this repository, located at sonar-basic/dotnet-demo
-
Navigate to the samples you want and restore dependencies (e.g:
core/getting-started/unit-testing-using-dotnet-test):dotnet restore
-
Run the application:
dotnet run
dotnet test-
Install SonarScanner:
dotnet tool install --global dotnet-sonarscanner
-
Start analysis:
dotnet tool install --global dotnet-sonarscanner dotnet sonarscanner begin /k:"project-key" /d:sonar.token="<token>" /d:sonar.host.url="http://localhost:9000" dotnet build # or 'dotnet build <path to project file or .sln file> --no-incremental' dotnet sonarscanner end /d:sonar.token="<token>"
NOTE: If we cannot execute
dotnet sonarscanner, try to open new terminal or reload the cmd. Or make sure the dotnet Path is in environment variables -
View results at
http://localhost:9000. Once completed you can get the result like this:

- https://docs.sonarsource.com/sonarqube-server/latest/
- https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/dotnet/installing/
- https://hub.docker.com/_/sonarqube
- https://docs.sonarsource.com/sonarqube-server/latest/server-installation/introduction/
- https://docs.sonarsource.com/sonarqube-server/latest/quality-standards-administration/managing-quality-gates/introduction-to-quality-gates/
- https://docs.sonarsource.com/sonarqube-community-build/analyzing-source-code/scanners/dotnet/introduction/
- Additionally, we can scan the sample from We can use this sample repo: https://github.com/dotnet/samples or any dotnet repo you want
MIT License.
