使用 Jenkins 的 Roslyn 分析器

Roslyn Analyzers with Jenkins

我们在 Visual Studio 2015 年使用了 SonarLint and StyleCop 分析器。这些在开发时工作得很好,但想知道在 Jenkins 构建期间是否可以 运行 这些?

我看过 SonarLint.Runner,所以我假设这是可能的。

我不太熟悉 Jenkins,但您始终可以将分析器作为 NuGet 包安装到项目中,并让它们在 MsBuild 构建过程中生成警告和错误:

  1. 将以下 2 个 NuGet 包安装到您要分析的项目中:SonarAnalyzer.CSharp and StyleCop.Analyzers.

  1. 可选择配置单个规则的严重性,如果您希望构建在出现警告时失败,则将警告视为错误。

  2. 使用 MSBuild 编译像这样配置的项目将导致分析器警告和错误以与编译器错误和警告相同的方式出现。您也应该能够在 Jenkins 中以相同的方式对待它们:

    "D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj" (default target) (2) ->
    (CoreCompile target) ->
      Class1.cs(13,17): warning CS0219: The variable 'a' is assigned but its value is never used [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(1,1): warning SA1652: Enable XML documentation output [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(1,1): warning SA1633: The file header is missing or not located at the top of the file. [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(13,23): warning SA1002: Semicolons must not be preceded by a space. [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(1,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(2,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(3,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(4,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(5,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(1,1): warning SA1652: Enable XML documentation output [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(1,1): warning SA1633: The file header is missing or not located at the top of the file. [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(5,77): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(17,76): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(18,74): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(28,22): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(32,84): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(13,19): warning S1854: Remove this useless assignment to local variable "a". [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(13,17): warning S1481: Remove this unused "a" local variable. [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
    
        18 Warning(s)
        0 Error(s)