当前位置: 代码迷 >> 综合 >> .NET Core 项目使用 SonarQube 来生成代码分析报告
  详细解决方案

.NET Core 项目使用 SonarQube 来生成代码分析报告

热度:17   发布时间:2024-01-25 05:35:37.0

1、下载解压sonarqube,双击运行StartSonar
在这里插入图片描述

注:必须安装java,且版本高于11

在这里插入图片描述
2、浏览器访问:http://localhost:9000/,点击Login,默认管理员账号和密码都是 admin,进入到 Sonar 的项目管理界面。
在这里插入图片描述
3、 安装 dotnet scanner

dotnet tool install --global dotnet-sonarscanner 

在这里插入图片描述

4、分析项目
跳转到你需要分析的项目的根目录。

在命令行工具当中分步执行以下命令:

dotnet sonarscanner begin /k:"iLearning" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="ee3602c8cfb60b2841bcf62fac9d7645cddf0507"
dotnet build
dotnet sonarscanner end /d:sonar.login="ee3602c8cfb60b2841bcf62fac9d7645cddf0507"

在这里插入图片描述

WARNING: The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis…
No analysable projects were found. SonarQube analysis will not be performed. Check the build summary report for details.
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
16:09:26.217 Post-processing failed. Exit code: 1

dotnet new sln

在这里插入图片描述

The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:

  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
  3. The begin, build and end steps have not all been launched from the same folder
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
dotnet msbuild -verison

16.3.0.46305

dotnet sln TestConsoleApp.sln add TestConsoleApp.csproj

在这里插入图片描述

  相关解决方案