0

我是 SonarQube 及其配置的新手。我的帖子与类似,但它是旧的,据我了解,解决方案中的几处发生了变化。英语不是我的母语,请耐心等待。

我使用 C# 插件 8.6.1 启动并运行了 SonarQube 8.3, 在此处输入图像描述

以及为 .Net Framework 4.6+ 的 MSBuild 运行的 SonarScanner 4.3。我没有编辑 ..\conf\sonar-scanner.properties 文件,

PS C:\test-demo> sonar-scanner
INFO: Scanner configuration file: C:\Sonar-Scanner-MSBuild\sonar-scanner-4.3.0.2102\bin\..\conf\sonar-scanner.properties

我在这个目录中有一个测试演示:

C:\test-demo

该目录有这些文件

在此处输入图像描述

这是 sonar-project.properties 文件配置,

# must be unique in a given SonarQube instance
sonar.projectKey=QRDemo
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=QRDemo
sonar.projectVersion=1.0
 
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set. 
sonar.sources=.
 
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
sonar.msbuild.testProjectPattern=*Tests;*UnitTests;*Demo
sonar.dotnet.visualstudio.solution.file="C:\\test-demo\\QrDemo.sln"

这是我要测试的代码,SonarQube 应该找到错误,

using QRCoder;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;

namespace QrDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0;

            string token = "Esto lo vamos a volver qr";
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(token, QRCodeGenerator.ECCLevel.Q);
            QRCode qrCode = new QRCode(qrCodeData);
            System.Drawing.Bitmap qrCodeImage = qrCode.GetGraphic(10);

            //Opcion A: Desde el memoryStream puedo retornar la imagen sin necesidad de crear fisicamente
            //using (MemoryStream ms = new MemoryStream())
            //{
            //    qrCodeImage.Save(ms, ImageFormat.Png);
            //}

            //Opción B: Se guarda un QR Fisico
            qrCodeImage.Save("imagen.png", ImageFormat.Png);
        }
    }
}

但是当我运行扫描仪时,我得到了这个,

PS C:\test-demo> sonar-scanner
INFO: Scanner configuration file: C:\Sonar-Scanner-MSBuild\sonar-scanner-4.3.0.2102\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\test-demo\sonar-project.properties
INFO: SonarScanner 4.3.0.2102
INFO: Java 11.0.6 Oracle Corporation (64-bit)
INFO: Windows 10 10.0 amd64
INFO: User cache: C:\Users\hpayares\.sonar\cache
INFO: Scanner configuration file: C:\Sonar-Scanner-MSBuild\sonar-scanner-4.3.0.2102\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\test-demo\sonar-project.properties
INFO: Analyzing on SonarQube server 8.3.1
INFO: Default locale: "es_CO", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=61ms
INFO: Server id: BF41A1F2-AXK_1XzT0nTmQjkDht7H
INFO: User cache: C:\Users\hpayares\.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=51ms
INFO: Load/download plugins (done) | time=144ms
INFO: Process project properties
INFO: Process project properties (done) | time=17ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=5ms
INFO: Project key: QRDemo
INFO: Base dir: C:\test-demo
INFO: Working dir: C:\test-demo\.scannerwork
INFO: Load project settings for component key: 'QRDemo'
INFO: Load project settings for component key: 'QRDemo' (done) | time=19ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=85ms
INFO: Load active rules
INFO: Load active rules (done) | time=1196ms
WARN: SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
INFO: Indexing files...
INFO: Project configuration:
INFO: 19 files indexed
INFO: Quality profile for cs: Sonar way
INFO: ------------- Run sensors on module QRDemo
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=31ms
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/C:/Users/hpayares/.sonar/cache/54f6535c111cefad0fb6a09ba3e61922/sonar-javascript-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO: Sensor SonarCSS Rules [cssfamily]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=0ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor C# Properties [csharp]
WARN: Property missing: 'sonar.cs.analyzer.projectOutPaths'. No protobuf files will be loaded for this project.
WARN: No Roslyn issues report found for this project.
INFO: Sensor C# Properties [csharp] (done) | time=16ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=0ms
INFO: Sensor C# [csharp]
INFO: Sensor C# [csharp] (done) | time=0ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=0ms
INFO: SCM Publisher No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
INFO: CPD Executor Calculating CPD for 0 files
INFO: CPD Executor CPD calculation finished (done) | time=0ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=31ms
INFO: Analysis report generated in 157ms, dir size=80 KB
INFO: Analysis report compressed in 47ms, zip size=12 KB
INFO: Analysis report uploaded in 31ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=QRDemo
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AXLeZwScZSZ5s3S2FZtb
INFO: Analysis total time: 12.890 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 14.453s
INFO: Final Memory: 6M/30M
INFO: ------------------------------------------------------------------------

在此处输入图像描述

我按照官方指南,看了别人的指南无济于事,我不知道我在这里做错了什么,¿你能帮帮我吗?

先感谢您。

4

1 回答 1

2

您需要使用 Scanner for MSBuild 来分析 .NET 项目。请关注SonarScanner for MSBuild文档页面。

于 2020-10-20T09:09:58.100 回答