19

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.

Psychoboy
  • 308
  • 1
  • 3
  • 10
  • Given that I didn't even manage to use Visual Studio to analyze the code, I guess we'll just need to wait and hope for version 1.1 when msbuild will be used again ... – peter Jul 15 '16 at 14:43
  • as of today, if you build using msbuild with xproj, it's only going to wrap the call to dotnet build. This doesn't allow SQ rules to follow with it and when the msbuild runner starts it like no build happened for it. – baywet Sep 15 '16 at 19:25
  • digging around it's not even possible to use sonarlint to bind asp.net core projects and have the static analysis work in VS. I guess they'd have to implement a new runner + adapt the current sonarlint plugin. – baywet Sep 15 '16 at 19:42
  • Hi @Psychoboy, we managed to get the code analysis to work with `sonar-scanner` (https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner), but could only get it to work on Windows, and not on Linux. I created a question about how to run it on Linux too: https://stackoverflow.com/questions/44114876/can-i-run-sonarqube-code-analysis-for-net-core-c-on-linux?noredirect=1#comment75249123_44114876. The command I show in that question works for me on Windows. – Mark Vincze May 22 '17 at 14:05

3 Answers3

4

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 .

Nicolas B.
  • 7,245
  • 17
  • 29
  • There is one important piece of information missing on the docs. ¿What MSBuild version is to be linked? For me, my project was .NET 4.6.1 using MSBuild 15.0. I just needed to set correctly the MSBuild using the new PATH. I that was it. – Ramon Gonzalez Feb 28 '18 at 21:00
1

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.

Jakob Möllås
  • 4,239
  • 3
  • 33
  • 61
  • it seems that the latest thing in dot net core is project.json for non Visual Studio developer, + xproj for visual studio developers, + csproj if you're doing dome kind of projects (like xamarin or so) https://github.com/aspnet/Home/issues/1451 – baywet Sep 15 '16 at 19:24
  • link to the documentation that indicates that "special" projects use csproj https://learn.microsoft.com/en-us/dotnet/articles/core/tutorials/target-dotnetcore-with-msbuild – baywet Sep 15 '16 at 20:23
1

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….
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
DDarwin
  • 11
  • 2