简体   繁体   English

SonarQube扫描仪未针对MSBuild分析C#代码

[英]C# code is not analysed by SonarQube scanner for MSBuild

SonarQube counts the c# lines in our projects, calculates the coverage and the duplications, but does not check for issues or code smells. SonarQube计算我们项目中的c#行,计算覆盖率和重复项,但不检查问题或代码异味。 For example, the following silly code does not generate any code smell : 例如,以下愚蠢的代码不会产生任何代码气味:

public static bool Silly()
        {
            int neverUsed = 0;
            var foo = false;
            foo = !!foo;
            var bar = "toto";
            bool isTrue = true;
            int one = 0;
            if (isTrue)
            {
                one = 1;
            }
            System.Console.WriteLine(one);
            if (bar != null & bar.Substring(0, 2).Equals("to"))
                return true;
            return false;
        }

We checked the c# quality profile (vanilla Sonar Way). 我们检查了c#质量配置文件(香草声纳方式)。 There is no file exclusion. 没有文件排除。 The analysis is working well with javascript code. 该分析与javascript代码配合良好。

We are using : 我们正在使用:

  • SonarQube 6.7.5 SonarQube 6.7.5
  • Jenkins 2.74 詹金斯2.74
  • SonarQube plugin for Jenkins 2.6.1 适用于Jenkins 2.6.1的SonarQube插件
  • SonarQube scanner for MSBuild 3.0.2 用于MSBuild 3.0.2的SonarQube扫描仪
  • MSBuild 14 MSBuild 14
  • SonarC# 6.2 声纳C#6.2

We followed : 我们遵循:

Here my jenkins build's configuration (vanilla) : 这是我的詹金斯构建的配置(香草):

在此处输入图片说明

In the build log, we found : 在构建日志中,我们发现:

  • La cible "RunCodeAnalysis" répertoriée dans un attribut BeforeTargets à "D:\\Program Files (x86)\\Jenkins\\workspace\\NouveauProjet.sonarqube\\bin\\targets\\SonarQube.Integration.targets (356,11)" n'existe pas dans le projet et sera ignorée. 以前的“目标”属性不正确Projet et seraignorée。
  • WARNING: Failed to fix Code Analysis ErrorLog file. 警告:无法修复代码分析ErrorLog文件。 Please check that VS 2015 Update 1 (or later) is installed. 请检查是否已安装VS 2015 Update 1(或更高版本)。

The first warning relates to FxCop, and probably means FxCop isn't installed on your build machine. 第一个警告与FxCop有关,很可能意味着您的构建计算机上未安装FxCop。 It won't affect the Roslyn analysis. 它不会影响罗斯林分析。

The second warning is relevant. 第二个警告是相关的。 Roslyn analysis reports are written as json files. Roslyn分析报告被编写为json文件。 However, the v1 of Roslyn produced invalid json in some cases. 但是,Roslyn的v1在某些情况下会生成无效的json。 The scanner checks that the file is valid json and if not attempts to correct it. 扫描程序将检查文件是否为有效的json,如果没有,则尝试对其进行更正。

This warning suggests that analysis is being performed but is producing an invalid file the scanner can't fix. 此警告表明正在执行分析,但正在生成扫描仪无法修复的无效文件。 Check the produced json report is actually valid json. 检查生成的json报告实际上是有效的json。 MSBuild 15 has a newer version of Roslyn that doesn't have this issue. MSBuild 15具有更新的Roslyn版本,没有这个问题。

[Update] MSBuild 15 is installed with the Build Tools for Visual Studio 2017, available here [更新] MSBuild 15已随Visual Studio 2017的构建工具一起安装,可在此处获得

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM