分析在SonarQube上添加C#自定义规则后出错

时间:2017-08-17 10:28:22

标签: c# msbuild sonarqube sonarqube-scan

我在VS2015中使用Roslyn为C#开发了一个自定义规则,我在SonarQube 6.4下部署它并在我的质量配置文件中激活它。

然后,我使用声纳扫描仪分析了同一目录下的几个.cs文件。但是我收到了这个错误

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)

规则停用后,我可以正常分析我的.cs文件

我无法使用SonarQube Scanner for MSBuild,因为它需要整个项目进行分析,但在我的情况下,我只能有一个.cs文件目录,这就是我需要的原因使用声纳扫描仪

我看到here已开发出一种解决方案,但目前是否可用?

是否有解决方案我可以使用sonar-scanner下的新规则分析我的文件?

1 个答案:

答案 0 :(得分:3)

使用Scanner for MSBuild是使用SonarQube对.Net代码进行任何分析的必要条件。由于您已经明确表明的原因:

  • C#规则(例如来自SonarC#)依赖于Roslyn框架
  • Roslyn是一个Microsoft框架,在编译代码期间开始使用
  • 基于Roslyn的分析器因此需要 msbuild 执行
  • .Net代码的SonarQube分析因此需要使用Scanner for MSBuild(与 msbuild 集成)

由于上述所有原因,无法使用任何其他扫描仪分析单个.cs文件。