RFF Release Scanner for MSBuild 4.0

407 views
Skip to first unread message

Michal Barczyk

unread,
Nov 24, 2017, 10:35:05 AM11/24/17
to sona...@googlegroups.com
Hello everyone,

We would like to release Sonar Scanner for MSBuild and we would like to get your feedback. 

This version brings support of analysing .Net Core and .Net Standard projects on Windows, Mac and Linux. Please note that won't work with SonarC# plugin versions 6.5 and 6.6.



We appreciate all help with testing. Please provide your feedback before 1st December 2017.

Cheers,
.Net team

chri...@gmail.com

unread,
Nov 28, 2017, 6:28:57 AM11/28/17
to SonarQube
Hi .Net team, thanks for your efforts to make this a reality!

I have a few questions:

- How do we run this on a unix-based platform? I have tried extracting the zip/setting the executable flags/running the exe's as we would on a Windows system, but I get the following error:(I'm running in a docker environment using the 'microsoft/dotnet:2.0-sdk' image provided by Microsoft):

SonarQube.Scanner.MSBuild.exe begin /n:INT004 /k:INT0044 /d:sonar.branch=PR-4 /s:%cd%/SonarQube.Analysis.xml
  hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarQube.Scanner.MSBuild.exe: cannot execute binary file: Exec format error
  script returned exit code 126

- How would we capture the test results from dotnet test/xunit so they are included in the analysis?

- How would we capture code coverage so they are included in the analysis?

Kind regards,
Chris Stylianou

valeri....@sonarsource.com

unread,
Nov 28, 2017, 12:10:07 PM11/28/17
to SonarQube
Hi Chris,

To analyze your .NET Core applications on Linux you need the following installed:
- SonarQube 6.7+ Note that the latest version of SonarC# is not compatible with older versions of SonarQube and you will have to upgrade your instance.
- Scanner for MSBuild 4.0+ (from this thread)
- SonarC# 6.7+ Note that the plugin is still not available on the SonarQube Update Center and you will have to install it manually
- .NET Core SDK 2.0 I doubt you could install earlier version anymore, but if you already have one, you will need to upgrade.
- Mono 
- JRE once you install it, you will have to set your JAVA_HOME variable, for example, on my machine the value is:
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/

A very important prerequisite is to make a couple of "bat" files in the Scanner for MSBuild folder executable. I extracted my Scanner for MSBuild at "~/Tools/Scanner" and the command to make the files executable is:

chmod u+x ~/Tools/Scanner/sonar-scanner-3.0.3.778/bin/*

Then to analyze your .NET Core application:

mono ~/Tools/Scanner/SonarQube.Scanner.MSBuild.exe begin /d:sonar.login=XXXXXXXXXXXXXXXXXXXXXXX /k:ConsoleApplication1 /d:sonar.host.url=http://localhost:9000
dotnet restore
dotnet msbuild /t:rebuild
mono ~/Tools/Scanner/SonarQube.Scanner.MSBuild.exe end /d:sonar.login=XXXXXXXXXXXXXXXXXXXXXXX

It is very important to use "dotnet msbuild /t:rebuild" instead of any other combination, because the current targets have a problem when building multiple target frameworks simultaneously with "dotnet build" (e.g. no "msbuild" and no /t:rebuild). For VSTS the workaround is to put /t:rebuild in the additional arguments on the Build Task in your build definition.

Another thing is that the .NET Core projects need to either have <ProjectGuid> property or to be added to a solution. ProjectGuid is not added if you create your projects with the dotnet command and the Guid is required by SonarQube. If you created your projects with Visual Studio you probably already have this property.

One last thing: if you are importing coverage data, you will most probably have to add <DebugType>Full</DebugType> in each of your projects. More information about this problem can be found here: https://github.com/Microsoft/vstest/issues/800

I hope this helps,
Valeri Hristov

chri...@gmail.com

unread,
Nov 28, 2017, 12:46:23 PM11/28/17
to SonarQube
Hi Valeri, 

I will give this a try but I'm confused as to why I need to install Mono to run this, as I thought the tools was being updated to run on dotnet core?

Also we do not target multiple frameworks inside our projects, so it okay to still use 'dotnet build/pack/publish'?

Kind regards,
Chris Stylianou

valeri....@sonarsource.com

unread,
Nov 29, 2017, 3:30:09 AM11/29/17
to SonarQube
Hi Chris,

Unfortunately we weren't able to port Scanner for MSBuild to .NET Core on time and we decided that having Mono, compared to the ability to use Linux agents is a minor nuisance, hence we went for a faster release. We will remove the Mono requirement in the future, but for the time being you should install it in order to run the scanner.

If you are building just one target framework (or configuration) you should be safe with the normal "dotnet build/pack/publish" sequence.

All the best,
Valeri



Reply all
Reply to author
Forward
Message has been deleted
0 new messages