Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running SonarQube against an ASP.Net Core solution/project

SonarQube has an MSBuild runner but .NET Core uses dotnet.exe to compile and msbuild just wraps that. I have tried using the MSBuild runner with no success against my ASP.NET Core solution. Using SonarQube Scanner works kind of.

Any suggestions on how I can utilize SonarQube with .NET Core? The static code analysis is what I am looking for.

like image 840
Psychoboy Avatar asked Jun 15 '16 16:06

Psychoboy


People also ask

How to analyze code using SonarQube in Visual Studio?

I created an ASP.NET Core application using Visual Studio, now we are going to analyze the code using SonarQube. Click on New Project in SonarQube running in browser. Next, we want to rebuild the project using the below command. Now go to SonarQube dashboard in browser and switch to your project, you can see the code analysis report as shown below.

Does SonarQube have an MSBuild runner?

SonarQube has an MSBuild runner but .NET Core uses dotnet.exe to compile and msbuild just wraps that. I have tried using the MSBuild runner with no success against my ASP.NET Core solution. Using SonarQube Scanner works kind of.

How to run a sonar project from a solution Directory?

Reach to the directory where you have kept the sonar-project.properties file. (where .sln file exists) with the following command cd [path of properties file],in our case it is IV. when you reach to your solution directory enter the following command sonar-runner, as shown below

How to start a SonarQube server?

SonarQube server is started locally. In order to verify the same, browse http://localhost:9000 in the browser and you will be able to see the landing page of SonarQube. Click on the project in the main menu. Click on + button mentioned on the right side of the page and click on "Create New Project". Provide the project key and display name.


3 Answers

With .csproj now being the de-facto format of .Net Core solutions, SonarQube support of such solutions comes with the SonarQube Scanner for MSBuild v2.3 .

like image 86
Nicolas B. Avatar answered Oct 20 '22 11:10

Nicolas B.


It seems .NET Core is switching from project.json to use .csproj and MSBuild. That may be available in .NET Core 1.1 or similar. At that time it may be possible to use MSBuild to build projects and have SonarQube pick that up.

See: https://blogs.msdn.microsoft.com/dotnet/2016/05/23/changes-to-project-json/

Whether that be a good thing or not remains to be seen I guess.

Also see this link for a possible workaround to use MSBuild to build .NET Core projects in the meantime (I have not tested it yet): https://learn.microsoft.com/en-us/dotnet/articles/core/tutorials/target-dotnetcore-with-msbuild

The .NET Core tooling is going to move from project.json to MSBuild based projects. We expect the first version of the .NET Core tools that use MSBuild to ship along with the next version of Visual Studio. However, it is possible to use MSBuild for .NET Core projects today, and this page shows how.

like image 37
Jakob Möllås Avatar answered Oct 20 '22 10:10

Jakob Möllås


I was able to get .NET Core builds working from the procedure on their site, with two things I'd like to point out….

  • When you run the SonarQube.Scanner.MSBuild.exe command lines, you must be in the same directory as your project file, and the location directory of the end command must match the start.
  • When the instructions say you must modify sonar.host.url to point to your server, you must uncomment the entire section of the file before doing the modification. Otherwise you've just inserted your server into a sonar.host.url line that is dead because it is commented out. This made me spin for a while before I really looked….
like image 27
DDarwin Avatar answered Oct 20 '22 09:10

DDarwin