SonarQube is a really great solution to monitor and track your technical debt over time. But wouldn’t it be great if the developer could already see in Visual Studio the impact that his commit will have to the sonar dashboard? If you use Visual Studio 2015 and the C# Plugin for SonarQube you can do this with the extension SonarLint.
The extension depends on the latest version of the C# Plugin – so make sure that you have the latest version (5.2) installed.
In Visual Studio install the extension in the “Extensions and Updated” dialog.
This adds a new Tile ‘SonarQube’ to your Team Explorer.
You can use this tile to connect to your SonarQube instance.
Once connected you can bind your current solution to a project from the SonarQube instance.
Now all the Errors and Warnings from your SonarQube project will show up in the error window in Visual Studio.
SonarLint uses Roslyn to perform the analysis so that you can use all tooling that you get from the roslyn compiler. You can suppress the message from within the code if you like.
You also can leverage the new features from the static code analysis in Visual Studio like only showing messages for the changed documents.
So that’s it. A really small extension with a very big impact. I’ve always been a big fan the FxCopy and the static code analysis – But I’ve always missed a central point to manage the rules and to monitor the output over time. SonarQube is perfect for that – but without a Visual Studio integration it was not a complete solution. SonarLint closes that gap and integrates the Visual Studio toolchain perfectly with SonarQube.
Where I can obtain data for connection?
To your Sonar instance? It’s the same URL you would use to connect to the web interface (port 9000 is the default).
Bind option is not enabled. What should I do??
What URL do you use? Can you access it with your browser?
Hello, if I created a VM in Azure with SonarQube on it, and integrated it with my VSTS build definition, do I also need to integrate SonarLint with Visual Studio to make the build definition run successfully? Or can the build definition succeed without SonarLint being integrated with Visual Studio?
You don’t need SonarLint. You can use SobarQube without it. But it’s nice to have the same errors in VisualStudio…
Hello, can SonarQube be installed on my VM, and then integrated with VSTS, without having to install SonarLint on my VS project? Or do I have to install SonarLint on my Visual studio project for the build definition on VSTS to run successfully and show my SonarQube results?
SonarLint is only a tool for the client integration of the SonarQube quality profile in VisualStudio. You don’t need this for SonarQube to work. And you don’t need it for the VSTS integration. You can use https://sonarcloud.io/ to test the integration. It’s free for open source projects.
Great, thanks! Awesome tutorials by the way!
Thanks 🙂
This is an awesome tutorial. Thank you for putting this together. Very helpful.
after successful each and everything not able to see any data, issues or even code on locally installed sonarqube using sonarlint in visual studio 2015 update3.
sonarqube version “sonarqube-6.7.2”
Ex Url: http://localhost:9000
any idea?
I am not able to view issues in sonarcloud even afer binding.. any idea why it is not ?
The binding is only to run the analysis locally in Visual studio. The results do not get uploaded automatically. You have to run the analysis locally – or better in the CI build.
Thanks MIke… How can i get results in sonarcloud?
Use a pipeline like this https://writeabout.net/2019/04/18/use-pull-request-decoration-in-azure-devops-with-sonarcloud/
Or here an example with YAML https://writeabout.net/2019/04/27/net-core-code-coverage-done-right/
Okay..Thanks a lot for that update.. I do not have a pipeline set up now. is there any other way other than that to show results in sonar cloud?
Yes. But it’s not recommended. Create a pipeline. It’s free! If not you can run the analysis locally from the command line https://docs.sonarqube.org/plugins/servlet/mobile?contentId=6954799#content/view/6954799
Thanks a lot…I update my sonar.host.url to sonarcloud.io… still when i run “dotnet sonarscanner begin /k:”AMD”” I get this error ” Failed to request and parse ‘http://localhost:9000/api/server/version’:”
This might be case sensitive. Have you checked that?
it is not picking the URL from “SonarQube.Analysis”…I updated the URL correcty
You can set it as a parameter with /d:sonar.host.url=… You also need the PAT. But I still recommend doing it in a pipeline…
Thanks a lot… it worked for me,,,, I ran start, analysis and End statements.. I am still seein project not configured in sonarcloud… do i need to do anything in sonarcloud to make it visible
No – the project is created automatically. Only the project key must be unique. If it is not showing up there is something wrong with the analysis. I always run it in the pipeline – so I don’t have a working example that runs locally, sorry.
Thanks…I have not configured a pipeline yet… so need more time to do that … I thought i will set up this way first. however I can not see that project in sonar…
It’s 5 minutes for .NET if you use the template! It’s worth the time…
Hello Mike, I am new to SonarQube. I connected to SonarQube server from Visual Studio 2017 and bound the solution to project from SonarQube server. This action generated .ruleset files for each project and .sonarlint folder and modified .proj files.
My question is, do I need to check-in all the .ruleset files and other changes? Is there a way to get the same issues on the development machine without doing all these changes (adding .ruleset files)?
Thank you in advance.
The analysis on the client is optional. Just run the it on the server – that’s more important. Just add .rulese and .sonarlint/ to your .gitignore file (I think in the VisualStudio template this sould already be the case). SonarLint helps to run the same rules (from the server) on all clients.
Thank you for writingg this