Sonarqube Integration with Visual Studio 2022 and VS Code
Overview
This article explains about Sonarqube and its plugins of visual studio. By using plugin, we can detect sonarqube issues on local machine upfront. So that our clean code would be pushed on version control system. Also we can enable Sonar scans on every build which is a part of CI pipeline
Sonarqube
SonarQube is an open-source platform designed to improve code quality and maintainability in software development projects. It is a static code analysis tool that performs automated code reviews, identifies issues, and provides insights into the health of your codebase. SonarQube is a valuable tool for developers, quality assurance teams, and project managers, helping them ensure the long-term quality and reliability of their software.
Key Features:
- Code Quality Metrics: SonarQube provides a range of metrics, including code complexity, code duplication, and code smells, to assess the overall quality of your code.
- Issue Detection: It identifies and reports on code issues, such as bugs, vulnerabilities, and maintainability problems.
- Support for Multiple Languages: SonarQube supports a wide variety of programming languages, making it versatile for different projects.
- Integration: It can be seamlessly integrated into popular CI/CD pipelines and development tools, enabling automated code analysis during the build process. Also we can enable Quality Gates on CI pipelines
- Custom Rules and Profiles: Developers can define custom coding rules and quality profiles to tailor SonarQube to their specific coding standards and requirements.
Develpment with Sonar

- SonarLint provides immediate feedback in your IDE as you write code so you can find and fix issues before a commit.
- SonarQube’s PR analysis fits into your CI/CD workflows with SonarQube’s PR analysis and use of quality gates.
- Quality gates keep code with issues from being released to production, a key tool in helping you incorporate the Clean as You Code methodology.
Prerequisites
Jdk 17 is required to run SonarLint plugin on system
Integration in Visual Studio 2022
- In Visual Studio, click Extensions -> Manage Extensions to open “Manage Extensions” window
- Search “SonarLint” and click download (as in screen below)
- Once Download is completed, please close all windows of Visual Studio to complete the extension installation
- Once all instances of Visual Studio are closed, VSIX Installer window opens with SonarLint installation task which is scheduled through Visual Studio. Click Modify to complete the installation.
- Once Installation is completed Open Visual Studio. You can notice "Sonarlint” item option under the Extensions menu which confirms SonarLint installation had completed successfully,
- To see errors of sonarlint for particular solution, Open Solution in Visual Studio and click on Analyze → Run Code Analysis → On Solution (Refer below screenshot)
- After Successful Code Analysis in Error tab you will see Sonarqube errors. Add filter on Tools Coulumn for Sonar Analyzer (Refer below screenshot)
Integration in Visual Studio Code
- Install Sonarlint Extension in VS Code by clicking on Extension tab
- Go to setting Enable verbose and analyzer log
- Now you will see problems after opening the files in VS Code for that particular file. (Refer below screenshot for step 2 and 3)
Challenges
- While SonarQube is a valuable tool, it's important to be aware of its limitations, which include occasional false positives.
- For large codebases, the analysis process can be resource-intensive, requiring substantial processing power and memory. This can lead to longer analysis times and higher resource costs.
- Sometime it is observed that Code Coverage is not visible in sonarqube for Dot Net 6 Project. Click here for the fix of same.
References
https://docs.sonarsource.com/sonarqube/latest/
https://community.sonarsource.com/t/code-coverage-not-shown-for-net-6-projects/56538/8
Comments
Post a Comment