【问题标题】:Sonarcloud not displaying issues for .net core app using dotnet-sonarscannerSonarcloud 未使用 dotnet-sonarscanner 显示 .net 核心应用程序的问题
【发布时间】:2020-11-17 22:30:33
【问题描述】:

我使用 .net core 3.1 创建了一个测试控制台应用程序,将其添加到 github,并使用 Sonarcloud.io 提供的模板设置了一个 GitHub 操作。

构建分析部分如下所示:

      .\.sonar\scanner\dotnet-sonarscanner begin /k:"<projectkey>" /o:"<org>" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.scanner.force-deprecated-java-version=true
      dotnet build --configuration Release --no-restore
      .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"

这构建良好并且没有报告错误。然而,当我去 sonarcloud.io 时,虽然我可以看到它已收到分析,但它没有显示任何问题,尽管我故意添加了一些:

master 分支显示如下:

然而,代码在代码选项卡中可见:

对于我看到的 PR:

但是个问题(当我使用 SonarLint 指向 sonarcloud.io 时,我可以在本地看到它们)。

我错过了什么?

【问题讨论】:

  • .\.sonar\scanner\dotnet-sonarscanner begin中提供属性sonar.sources=.
  • @SouravAtta 这样做后我收到此错误:File Program.cs can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
  • Program.cs 文件被索引两次意味着您可以使用声纳属性将其排除一次 sonar.exclusions=&lt;path of file&gt; 这将解决问题。
  • 我已经添加了/d:sonar.sources=. /d:sonar.exclusions=/SonarQubeTest/Program.cs,它仍然给索引两次同样的错误。很困惑,为什么我要指定源文件夹(带有. 的根目录)然后排除文件?我当然不希望他们被排除在外?
  • 除了 src 文件夹之外,您是否还有其他地方的 Program.cs。在sonar.sources 中,只需提供像这样的源文件夹sonar.source=src\** SonarQubeTest 是您的源文件夹吗?

标签: .net-core sonarqube static-analysis sonarcloud


【解决方案1】:

事实证明这并没有显示任何问题,因为它将我的所有文件都视为测试代码。我将整个 repo 创建为 Sonarcloud 测试,我的项目名为 SonarCloudTest.csproj,Sonar 有一些关于代码分类的正则表达式规则。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-01
    • 2020-02-20
    • 2020-03-30
    • 1970-01-01
    • 2019-09-25
    • 2022-08-02
    • 2020-12-23
    • 2021-09-20
    相关资源
    最近更新 更多