【发布时间】:2018-02-10 19:21:09
【问题描述】:
我有一个 C#/.NET 项目,我想使用 SonarQube(C# 语言)进行扫描。
我正在让扫描通过,但有很多错误(超过 200 个重复错误)
Provide an 'AssemblyVersion' attribute for this assembly.
上述消息重复了很多次,是我在报告中看到的大多数 SonarQube 错误的原因。
SonarQube 属性文件
# Comma-separated paths to directories with sources (required)
#sonar.sources=controllers,services
sonar.sources=.
# Language
sonar.language=cs
sonar.visualstudio.solution=ProjectName.sln
sonar.sourceEncoding=UTF-8
sonar.cobol.copy.diretories=/copy
sonar.visualstudio.enable=true
我什至在我的项目中运行了这个 msbuild(使用我从 https://www.microsoft.com/en-us/download/details.aspx?id=48159 下载的 MSBuild.exe 版本 14)批处理文件
C:\Users\pwrdbyadmin\Desktop\sonar-scanner-msbuild-3.0.2.656\SonarQube.Scanner.MSBuild.exe begin /k:"org.sonarqube:sonarqube-scanner-msbuild" /n:"ProjectName" /v:"1.0"
"C:\Program Files (x86)\MSBuild\14.0\Bin\amd64\MSBuild.exe" /t:Rebuild
C:\Users\pwrdbyadmin\Desktop\sonar-scanner-msbuild-3.0.2.656\SonarQube.Scanner.MSBuild.exe end
下载 SonarQube 6.5 并运行以下命令启动服务器
C:\Users\pwrdbyadmin\Desktop\sonarqube-6.5\bin\windows-x86-32\StartSonar.bat
我在项目中运行的命令
C:\Users\username\Desktop\sonar-scanner-3.0.3.778-windows\bin\sonar-scanner.bat
我仍然无法解决项目中的许多 .NET 错误。
如何解决在我的项目上运行 SonarQube 后出现的这些明显的 C# 错误,我是否需要安装 Visual Studio,我是否需要在 Visual Studio 中构建我的项目?我需要遵循哪些正确步骤来扫描我的项目?
编辑
新的三班轮允许分析工作,最后不会出现任何权限不足错误。我在我的 3 行命令中使用了 VS 2017 的最新 MSBuild.exe
C:\Users\<UserName>\Desktop\sonar-scanner-msbuild-3.0.2.656\SonarQube.Scanner.MSBuild.exe begin /d:"sonar.host.url=http://localhost:9000" /d:"sonar.login=<login>" /d:"sonar.password=<password>" /k:"org.sonarqube:sonarqube-scanner-msbuild" /n:"<ProjectName>" /v:"1.0"
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" /t:Rebuild
C:\Users\<UserName>\Desktop\sonar-scanner-msbuild-3.0.2.656\SonarQube.Scanner.MSBuild.exe end /d:"sonar.login=<login>" /d:"sonar.password=<password>"
尽管使用了更新的命令序列,但我的报告中仍然出现程序集版本错误。
我是否需要删除项目并重新分析。此外,即使我的 3 班轮显示使用 MSBuild 15,也会出现黄色通知,说我正在使用 MSBuild 12。我不知道为什么。
更新:代码异味分析中重复文件/文件夹的屏幕截图。
【问题讨论】:
-
this 有帮助吗? Source docs
-
我之前发现了这个,并在上面的代码中使用了三个 liner 来执行 msbuild 的 sonarscanner。运行 3 班轮后,我是否只是在我的项目上重新运行 sonar-scanner.bat?
-
我希望在您运行 3 行之后,您的分析就完成了。您不需要运行 .bat 文件。
-
您的 SonarC# 插件是什么版本?您是否在解决方案中使用共享项目?您能否上传构建中的完整日志并在此处发布链接,以便我们更好地诊断?
-
感谢您的回复。 SonarQube 是 6.5 版,Sonar Scanner 是 3.0.3.778 版,sonar-csharp-plugin-5.10.1.1411。我收到一条警告说使用 MSBuild 14 以获得最佳分析结果。我在我的项目目录中运行 sonar-scanner.bat。我在帖子中将 MSBuild 更新为 14。如何在 sonar-scanner.bat 中指向它?
标签: c# asp.net msbuild sonarqube