当前位置:   article > 正文

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

c#静态代码扫描工具

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>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

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

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/973132
推荐阅读
  

闽ICP备14008679号