0
votes

I developed a custom rule for C# using Roslyn in VS2015, I deployed it under SonarQube 6.4 and activated it in my quality profile.

Then, I analyzed several .cs files under the same directory using sonar-scanner. But I got this error

ERROR: Error during SonarQube Scanner execution
java.lang.IllegalArgumentException: Custom and 3rd party Roslyn analyzers are only by MSBuild 14. Either use MSBuild 14, or disable the custom/3rd party Roslyn analyzers in your quality profile.
    at org.sonar.plugins.csharp.CSharpSensor.analyze(CSharpSensor.java:141)
    at org.sonar.plugins.csharp.CSharpSensor.executeInternal(CSharpSensor.java:112)
    at org.sonar.plugins.csharp.CSharpSensor.execute(CSharpSensor.java:79)
    at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
    at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:57)
    at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:49)
    at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:74)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:175)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:262)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:257)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:247)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
    at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
    at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
    at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:118)
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:117)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
    at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
    at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Once the rule deactivated, I can analyze my .cs files normally

I cannot use SonarQube Scanner for MSBuild, because it requires a whole project to analyze, but in my case, I can only have a directory of .cs files, this is why I need to use sonar-scanner

I saw here that a solution has been developed, but is it available currently?

Is there a solution I can analyze my files with my new rule under sonar-scanner?

1

1 Answers

3
votes

Using the Scanner for MSBuild is a requirement for any analysis of .Net code with SonarQube. For reasons you've already made clear in fact:

  • C# rules (e.g. from SonarC#) rely on the Roslyn framework
  • Roslyn is a Microsoft framework, which kicks in during compilation of the code
  • Roslyn-based analyzers therefore require msbuild execution
  • SonarQube analysis of .Net code therefore requires to use the Scanner for MSBuild (which integrates with msbuild)

For all above reasons, it is not possible to analyze individual .cs files with any other scanner.