简体   繁体   中英

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. 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). There is no file exclusion. The analysis is working well with javascript code.

We are using :

  • SonarQube 6.7.5
  • Jenkins 2.74
  • SonarQube plugin for Jenkins 2.6.1
  • SonarQube scanner for MSBuild 3.0.2
  • MSBuild 14
  • SonarC# 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.
  • WARNING: Failed to fix Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed.

The first warning relates to FxCop, and probably means FxCop isn't installed on your build machine. It won't affect the Roslyn analysis.

The second warning is relevant. Roslyn analysis reports are written as json files. However, the v1 of Roslyn produced invalid json in some cases. The scanner checks that the file is valid json and if not attempts to correct it.

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. MSBuild 15 has a newer version of Roslyn that doesn't have this issue.

[Update] MSBuild 15 is installed with the Build Tools for Visual Studio 2017, available here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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