C#语言接入Sonar代码静态扫描

C#语言接入Sonar代码静态扫描相较于Java、Python来说,相对麻烦一些。Sonar检测C#代码时需要预先编译,而且C#代码必须用MSbuid进行编译,如果需要使用SonarQube对C#进行代码质量分析,则需要下载Sonar-Scanner-MSBuild和MSBuild,其中要求MSBuild在V14.0以上。
在这里插入图片描述
在这里插入图片描述
修改SonarQube.Analysis.xml文件,要修改的地方只是关于SonarQube服务器的一些配置,如服务器URL、USER、PASSWORD等,详细配置修改如下:

<?xml version="1.0" encoding="utf-8" ?>
<!--
  This file defines properties which would be understood by the SonarQube Scanner for MSBuild, if not overridden (see below)
  By default the SonarScanner.MSBuild.exe picks-up a file named SonarQube.Analysis.xml in the folder it
  is located (if it exists). It is possible to use another properties file by using the /s:filePath.xml flag

  The overriding strategy of property values is the following:
  - A project-specific property defined in the MSBuild *.*proj file (corresponding to a SonarQube module) can override:
  - A property defined in the command line (/d:propertyName=value) has which can override:
  - A property defined in the SonarQube.Analysis.xml configuration file [this file] which can override:
  - A property defined in the SonarQube User Interface at project level which can override:
  - A property defined in the SonarQube User Interface at global level which can't override anything.

  Note that the following properties cannot be set through an MSBuild project file or an SonarQube.Analysis.xml file:
  sonar.projectName, sonar.projectKey, sonar.projectVersion
  The following flags need to be used to set their value: /n:[SonarQube Project Name] /k:[SonarQube Project Key] /v:[SonarQube Project Version]

-->
<SonarQubeAnalysisProperties  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">

  <!--
  <Property Name="sonar.host.url">http://localhost:9000</Property>

  <Property Name="sonar.login"></Property>
  <Property Name="sonar.password"></Property>
  -->

  <!-- Required only for versions of SonarQube prior to 5.2 -->
  <!--
  <Property Name="sonar.jdbc.url">jdbc:jtds:sqlserver://mySqlServer/sonar;instance=SQLEXPRESS;SelectMethod=Cursor</Property>
  <Property Name="sonar.jdbc.username">sonar</Property>
  <Property Name="sonar.jdbc.password">sonar</Property>
  -->
  
  <Property Name="sonar.host.url">http://10.10.20.53:9000</Property>

  <Property Name="sonar.login"></Property>
  <Property Name="sonar.password"></Property>
  
  <Property Name="sonar.jdbc.url">jdbc:mysql://10.10.20.53:3306/sonar?useUnicode=true;characterEncoding=utf8;rewriteBatchedStatements=true;useConfigs=maxPerformance;useSSL=false</Property>
  <Property Name="sonar.jdbc.username">root</Property>
  <Property Name="sonar.jdbc.password"></Property>

</SonarQubeAnalysisProperties>

在这里插入图片描述
在项目根目录下打开cmd窗口,一步步执行命令即可。

https://www.cnblogs.com/jinjiangongzuoshi/p/11648785.html

https://mp.weixin.qq.com/s/Jj6lzZmuRIBvGgQ8e_26Yw

已标记关键词 清除标记
相关推荐
<div><p>I've recently upgraded our SonarQube server from a 5.x version to a 7.2 version. I've launched the database migration like it is described in the documentation, and the server seems correctly upgraded. The projects was correctly analyzed with the previous version of SonarQube, but now with the 7.2 version I have these following error messages :</p> <pre><code>2018-08-16T07:43:28.8310428Z ##[error]08:43:28.822 WARN: Property missing: 'sonar.cs.analyzer.projectOutPaths'. No protobuf files will be loaded for this project. 2018-08-16T07:43:28.8311036Z 08:43:28.822 WARN: Property missing: 'sonar.cs.analyzer.projectOutPaths'. No protobuf files will be loaded for this project. 2018-08-16T07:43:28.8313994Z ##[error]08:43:28.822 WARN: No roslyn issues report not found for this project. 2018-08-16T07:43:28.8315503Z 08:43:28.822 WARN: No roslyn issues report not found for this project. </code></pre> <p>I have also a lot of error messages like this :</p> <pre><code>2018-08-16T07:43:27.8889117Z ##[error]08:43:27.885 WARN: File 'S:\VSTS\_work\123\s\WSDAL\WSDAL\WSDAL.csproj' is ignored because it doesn't belong to the forced language 'cs' 2018-08-16T07:43:27.8889699Z 08:43:27.885 WARN: File 'S:\VSTS\_work\123\s\WSDAL\WSDAL\WSDAL.csproj' is ignored because it doesn't belong to the forced language 'cs' 2018-08-16T07:43:27.8890597Z ##[error]08:43:27.885 WARN: File 'S:\VSTS\_work\123\s\WSDAL\WSDAL.nsi' is ignored because it doesn't belong to the forced language 'cs' 2018-08-16T07:43:27.8891507Z 2018-08-16T07:43:27.8893986Z ##[error]08:43:27.885 WARN: File 'S:\VSTS\_work\123\s\WSDAL\WSDAL.sln' is ignored because it doesn't belong to the forced language 'cs' 2018-08-16T07:43:27.8896320Z 08:43:27.885 WARN: File 'S:\VSTS\_work\123\s\WSDAL\WSDAL.sln' is ignored because it doesn't belong to the forced language 'cs' </code></pre> <p>The analyze is launched from VSTS with the SonarQube plugin and with the additional parameters :</p> <pre><code>sonar.sources=. sonar.verbose=true sonar.language=cs sonar.dotnet.visualstudio.testProjectPattern=*.Test sonar.exclusions=UITests/**,UnitTests/** sonar.sourceEncoding=UTF-8 </code></pre> <p>With the "verbose" option, I have these informations :</p> <pre><code>2018-08-16T07:43:18.7068176Z ============================================================================== 2018-08-16T07:43:19.5912144Z [command]C:\Windows\system32\cmd.exe /D /S /C "S:\VSTS\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\4.3.0\sonar-scanner\bin\sonar-scanner.bat" 2018-08-16T07:43:19.5912599Z INFO: Scanner configuration file: S:\VSTS\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\4.3.0\sonar-scanner\bin\..\conf\sonar-scanner.properties 2018-08-16T07:43:19.5912936Z INFO: Project root configuration file: NONE 2018-08-16T07:43:19.5913156Z 08:43:19.166 INFO: SonarQube Scanner 3.2.0.1227 2018-08-16T07:43:19.5913401Z 08:43:19.166 INFO: Java 1.8.0_181 Oracle Corporation (32-bit) 2018-08-16T07:43:19.5913632Z 08:43:19.166 INFO: Windows Server 2012 R2 6.3 x86 2018-08-16T07:43:19.5913862Z 08:43:19.291 DEBUG: keyStore is : 2018-08-16T07:43:19.5914074Z 08:43:19.291 DEBUG: keyStore type is : jks 2018-08-16T07:43:19.5914289Z 08:43:19.291 DEBUG: keyStore provider is : 2018-08-16T07:43:19.5915184Z 08:43:19.291 DEBUG: init keystore 2018-08-16T07:43:19.5915409Z 08:43:19.291 DEBUG: init keymanager of type SunX509 2018-08-16T07:43:19.5915658Z 08:43:19.432 DEBUG: Create: C:\Users\yannick\.sonar\cache 2018-08-16T07:43:19.5915896Z 08:43:19.432 INFO: User cache: C:\Users\yannick\.sonar\cache 2018-08-16T07:43:19.5916159Z 08:43:19.447 DEBUG: Create: C:\Users\yannick\.sonar\cache\_tmp 2018-08-16T07:43:19.5916398Z 08:43:19.447 DEBUG: Extract sonar-scanner-api-batch in temp... 2018-08-16T07:43:19.5916636Z 08:43:19.447 DEBUG: Get bootstrap index... 2018-08-16T07:43:19.5916872Z 08:43:19.447 DEBUG: Download: http://SonarQubeServer:9999/batch/index 2018-08-16T07:43:19.5917121Z 08:43:19.494 DEBUG: Get bootstrap completed 2018-08-16T07:43:19.5917341Z 08:43:19.510 DEBUG: Create isolated classloader... 2018-08-16T07:43:19.5917572Z 08:43:19.510 DEBUG: Start temp cleaning... 2018-08-16T07:43:19.5917783Z 08:43:19.510 DEBUG: Temp cleaning done 2018-08-16T07:43:19.5918014Z 08:43:19.510 DEBUG: Execution getVersion 2018-08-16T07:43:19.5918225Z 08:43:19.525 INFO: SonarQube server 7.2.1 2018-08-16T07:43:19.5918575Z 08:43:19.525 INFO: Default locale: "en_US", source code encoding: "UTF-8" 2018-08-16T07:43:19.5918833Z 08:43:19.525 DEBUG: Work directory: S:\VSTS\_work\123\s\.scannerwork 2018-08-16T07:43:19.5919082Z 08:43:19.525 DEBUG: Execution execute 2018-08-16T07:43:19.7662081Z 08:43:19.760 INFO: Publish mode 2018-08-16T07:43:19.9390673Z 08:43:19.932 INFO: Load global settings 2018-08-16T07:43:20.0043807Z 08:43:19.978 DEBUG: GET 200 http://SonarQubeServer:9999/api/settings/values.protobuf | time=46ms 2018-08-16T07:43:20.0292709Z 08:43:20.025 INFO: Load global settings (done) | time=93ms 2018-08-16T07:43:20.0369335Z 08:43:20.025 INFO: Server id: EsA58sX698qSes654w 2018-08-16T07:43:20.0492805Z 08:43:20.041 INFO: User cache: C:\Users\yannick\.sonar\cache 2018-08-16T07:43:20.4268501Z 08:43:20.416 INFO: Load/download plugins 2018-08-16T07:43:20.4271693Z 08:43:20.416 INFO: Load plugins index 2018-08-16T07:43:20.4353642Z 08:43:20.432 DEBUG: GET 200 http://SonarQubeServer:9999/api/plugins/installed | time=16ms 2018-08-16T07:43:20.4895763Z 08:43:20.479 INFO: Load plugins index (done) | time=63ms 2018-08-16T07:43:20.5094751Z 08:43:20.494 INFO: Load/download plugins (done) | time=78ms 2018-08-16T07:43:20.5569127Z 08:43:20.541 DEBUG: Plugins: 2018-08-16T07:43:20.5575528Z 08:43:20.541 DEBUG: * SonarPython 1.10.0.2131 (python) 2018-08-16T07:43:20.5575997Z 08:43:20.541 DEBUG: * SonarGo 1.1.0.1612 (go) 2018-08-16T07:43:20.5576307Z 08:43:20.541 DEBUG: * Svn 1.8.0.1168 (scmsvn) 2018-08-16T07:43:20.5576629Z 08:43:20.541 DEBUG: * SonarJS 4.2.1.6529 (javascript) 2018-08-16T07:43:20.5576929Z 08:43:20.541 DEBUG: * SonarC# 7.3.0.5690 (csharp) 2018-08-16T07:43:20.5577237Z 08:43:20.541 DEBUG: * SonarJava 5.6.0.15032 (java) 2018-08-16T07:43:20.5577533Z 08:43:20.541 DEBUG: * LDAP 2.2.0.608 (ldap) 2018-08-16T07:43:20.5577842Z 08:43:20.541 DEBUG: * Git 1.4.1.1128 (scmgit) 2018-08-16T07:43:20.5578172Z 08:43:20.541 DEBUG: * SonarFlex 2.4.0.1222 (flex) 2018-08-16T07:43:20.5578472Z 08:43:20.541 DEBUG: * SonarXML 1.5.1.1452 (xml) 2018-08-16T07:43:20.5578780Z 08:43:20.541 DEBUG: * SonarPHP 2.14.0.3569 (php) 2018-08-16T07:43:20.5579084Z 08:43:20.541 DEBUG: * SonarTS 1.7.0.2893 (typescript) 2018-08-16T07:43:20.5720186Z 08:43:20.557 INFO: Loaded core extensions: 2018-08-16T07:43:20.9135176Z 08:43:20.900 INFO: Process project properties 2018-08-16T07:43:20.9203852Z 08:43:20.916 DEBUG: Process project properties (done) | time=16ms 2018-08-16T07:43:20.9398896Z 08:43:20.932 INFO: Load project repositories 2018-08-16T07:43:21.4140553Z 08:43:21.400 DEBUG: GET 200 http://SonarQubeServer:9999/batch/project.protobuf?key=project_key | time=468ms 2018-08-16T07:43:21.5284145Z 08:43:21.525 INFO: Load project repositories (done) | time=593ms 2018-08-16T07:43:21.6615142Z 08:43:21.652 DEBUG: Available languages: 2018-08-16T07:43:21.6616619Z 08:43:21.652 DEBUG: * Python => "py" 2018-08-16T07:43:21.6616940Z 08:43:21.652 DEBUG: * Go => "go" 2018-08-16T07:43:21.6617249Z 08:43:21.652 DEBUG: * JavaScript => "js" 2018-08-16T07:43:21.6617534Z 08:43:21.652 DEBUG: * C# => "cs" 2018-08-16T07:43:21.6617827Z 08:43:21.652 DEBUG: * Java => "java" 2018-08-16T07:43:21.6618165Z 08:43:21.652 DEBUG: * Flex => "flex" 2018-08-16T07:43:21.6618457Z 08:43:21.652 DEBUG: * XML => "xml" 2018-08-16T07:43:21.6618733Z 08:43:21.652 DEBUG: * PHP => "php" 2018-08-16T07:43:21.6619030Z 08:43:21.652 DEBUG: * TypeScript => "ts" 2018-08-16T07:43:21.6684968Z 08:43:21.666 INFO: Load quality profiles 2018-08-16T07:43:21.6864786Z 08:43:21.682 DEBUG: GET 200 http://SonarQubeServer:9999/api/qualityprofiles/search.protobuf?projectKey=project_key | time=16ms 2018-08-16T07:43:21.6911948Z 08:43:21.682 INFO: Load quality profiles (done) | time=16ms 2018-08-16T07:43:21.7055123Z 08:43:21.697 INFO: Load active rules 2018-08-16T07:43:21.7292078Z 08:43:21.713 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=cs-sonar-way-40297&p=1&ps=500 | time=16ms 2018-08-16T07:43:21.8274962Z 08:43:21.822 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=java-sonar-way-05385&p=1&ps=500 | time=62ms 2018-08-16T07:43:21.8578910Z 08:43:21.854 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=TR5ERPD85D3EEE&p=1&ps=500 | time=16ms 2018-08-16T07:43:21.8703088Z 08:43:21.869 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=ER6DFX8I65d&p=1&ps=500 | time=15ms 2018-08-16T07:43:21.8942153Z 08:43:21.885 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=DE5DD5OPP67DD&p=1&ps=500 | time=16ms 2018-08-16T07:43:21.9363457Z 08:43:21.916 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=js-sonar-way-28294&p=1&ps=500 | time=31ms 2018-08-16T07:43:21.9594956Z 08:43:21.947 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=DDDD5FECDVSDQ&p=1&ps=500 | time=15ms 2018-08-16T07:43:21.9782101Z 08:43:21.963 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=DSCDSQCDSQCD&p=1&ps=500 | time=16ms 2018-08-16T07:43:21.9989077Z 08:43:21.994 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=DSQDFSQCDSQCDS&p=1&ps=500 | time=15ms 2018-08-16T07:43:22.0113544Z 08:43:22.010 INFO: Load active rules (done) | time=313ms 2018-08-16T07:43:22.0179051Z 08:43:22.010 INFO: Load metrics repository 2018-08-16T07:43:22.0256465Z 08:43:22.010 DEBUG: GET 200 http://SonarQubeServer:9999/api/metrics/search?f=name,description,direction,qualitative,custom&ps=500&p=1 | time=0ms 2018-08-16T07:43:22.0365801Z 08:43:22.025 INFO: Load metrics repository (done) | time=15ms 2018-08-16T07:43:22.0427992Z 08:43:22.041 DEBUG: SCM Step is disabled by configuration 2018-08-16T07:43:22.0493558Z 08:43:22.041 INFO: Project key: project_key 2018-08-16T07:43:22.0494085Z 08:43:22.041 INFO: Project base dir: S:\VSTS\_work\123\s 2018-08-16T07:43:22.0503378Z 08:43:22.041 DEBUG: Start recursive analysis of project modules 2018-08-16T07:43:22.0511419Z 08:43:22.041 INFO: ------------- Scan project 2018-08-16T07:43:22.2015446Z 08:43:22.197 INFO: Load server rules 2018-08-16T07:43:22.2897220Z 08:43:22.275 DEBUG: GET 200 http://SonarQubeServer:9999/api/rules/list.protobuf | time=78ms 2018-08-16T07:43:22.3396578Z 08:43:22.307 INFO: Load server rules (done) | time=110ms 2018-08-16T07:43:22.3479690Z 08:43:22.338 INFO: Base dir: S:\VSTS\_work\123\s 2018-08-16T07:43:22.3480392Z 08:43:22.338 INFO: Working dir: S:\VSTS\_work\123\s\.scannerwork 2018-08-16T07:43:22.3491581Z 08:43:22.338 INFO: Source paths: . 2018-08-16T07:43:22.3493099Z 08:43:22.338 INFO: Source encoding: UTF-8, default locale: en_US 2018-08-16T07:43:22.4591820Z 08:43:22.447 DEBUG: Declared extensions of language Python were converted to sonar.lang.patterns.py : **/*.py 2018-08-16T07:43:22.4592818Z 08:43:22.447 DEBUG: Declared extensions of language Go were converted to sonar.lang.patterns.go : **/*.go 2018-08-16T07:43:22.4593300Z 08:43:22.447 DEBUG: Declared extensions of language JavaScript were converted to sonar.lang.patterns.js : **/*.js,**/*.jsx,**/*.vue 2018-08-16T07:43:22.4593740Z 08:43:22.447 DEBUG: Declared extensions of language C# were converted to sonar.lang.patterns.cs : **/*.cs 2018-08-16T07:43:22.4594149Z 08:43:22.447 DEBUG: Declared extensions of language Java were converted to sonar.lang.patterns.java : **/*.java,**/*.jav 2018-08-16T07:43:22.4594594Z 08:43:22.447 DEBUG: Declared extensions of language Flex were converted to sonar.lang.patterns.flex : **/*.as 2018-08-16T07:43:22.4594992Z 08:43:22.447 DEBUG: Declared extensions of language XML were converted to sonar.lang.patterns.xml : **/*.xml,**/*.xsd,**/*.xsl 2018-08-16T07:43:22.4595455Z 08:43:22.447 DEBUG: Declared extensions of language PHP were converted to sonar.lang.patterns.php : **/*.php,**/*.php3,**/*.php4,**/*.php5,**/*.phtml,**/*.inc 2018-08-16T07:43:22.4595960Z 08:43:22.447 DEBUG: Declared extensions of language TypeScript were converted to sonar.lang.patterns.ts : **/*.ts,**/*.tsx 2018-08-16T07:43:22.4596303Z 08:43:22.447 INFO: Language is forced to cs 2018-08-16T07:43:22.4682965Z 08:43:22.463 DEBUG: Initializers : 2018-08-16T07:43:22.4691697Z 08:43:22.463 INFO: Index files </code></pre> <p>I really don't understand what is the problem. I've tried to find a solution on internet, but without success. Any idea or solution about these issues please ?</p><p>该提问来源于开源项目:SonarSource/sonar-dotnet</p></div>
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页