如何在C#.NET项目上运行SonarQube?

Vah*_*ahe 5 c# asp.net msbuild sonarqube

我有一个C#/ .NET项目,我想用SonarQube(C#语言)扫描.

我正在通过扫描,但有很多错误(超过200个重复错误)

Provide an 'AssemblyVersion' attribute for this assembly.
Run Code Online (Sandbox Code Playgroud)

上面的消息重复多次,占我在报告中看到的大部分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
Run Code Online (Sandbox Code Playgroud)

我甚至跑这的MSBuild(使用MSBuild.exe版本14这是我从下载https://www.microsoft.com/en-us/download/details.aspx?id=48159)批处理文件在我的项目

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
Run Code Online (Sandbox Code Playgroud)

下载SonarQube 6.5并运行以下命令启动服务器

C:\Users\pwrdbyadmin\Desktop\sonarqube-6.5\bin\windows-x86-32\StartSonar.bat
Run Code Online (Sandbox Code Playgroud)

命令我在项目中运行

C:\Users\username\Desktop\sonar-scanner-3.0.3.778-windows\bin\sonar-scanner.bat
Run Code Online (Sandbox Code Playgroud)

我仍然无法解决项目中的许多.NET错误.

如何在我的项目上运行SonarQube后解决这些明显的C#错误,我是否需要安装Visual Studio,是否需要在Visual Studio中构建我的项目?扫描我的项目需要遵循哪些正确的步骤?

编辑

新的三个班轮允许分析工作,最后没有出现任何Insufficient Privilege错误.我在我的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>"
Run Code Online (Sandbox Code Playgroud)

尽管使用了更新的命令序列,我仍然在报告中收到程序集版本错误.

我是否需要删除项目并重新分析.此外,甚至认为我的3班轮显示MSBuild 15使用黄色通知出现说我正在使用MSBuild 12.我不知道为什么.

更新:Code Smell Analysis中重复文件/文件夹的屏幕截图.

在此输入图像描述

Man*_*ani 3

我不确定 SonarQube.Properties 文件在哪里使用。我在我的设置中找不到这个。

确保您正在扫描的所有项目都有“Properties”文件夹,并且在包含程序集版本的 AssemblyInfo.cs 下。该文件必须包含在项目中。您可以从 Visual Studio 中看到这一点。

确保您已在 SonarQube.Analysis.xml 中提供了 SonarQube 地址和身份验证详细信息

sonar.host.url - SonarQube 服务器的 URL sonar.login - 具有执行分析权限的用户的分析令牌。仅当 Anonymous 没有时才需要

仅使用这些行创建一个新的 bat 文件。

<local path>/SonarQube.Scanner.MSBuild.exe begin /k:"<SomeProjectNameKey>" /n:"<YourProjectName>" /v:"1.0"
<local path>/MSBuild.exe /t:Rebuild /tv:15.0 /p:VisualStudioVersion=15.0
<local path>/SonarQube.Scanner.MSBuild.exe end
Run Code Online (Sandbox Code Playgroud)

bat 文件应位于项目所在的同一文件夹中

文档参考https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild