【发布时间】: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=<path of file>这将解决问题。 -
我已经添加了
/d:sonar.sources=. /d:sonar.exclusions=/SonarQubeTest/Program.cs,它仍然给索引两次同样的错误。很困惑,为什么我要指定源文件夹(带有.的根目录)然后排除文件?我当然不希望他们被排除在外? -
除了 src 文件夹之外,您是否还有其他地方的 Program.cs。在
sonar.sources中,只需提供像这样的源文件夹sonar.source=src\**SonarQubeTest 是您的源文件夹吗?
标签: .net-core sonarqube static-analysis sonarcloud