Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-67291

Parse MSBuild-compatible diagnostic with (line,col,line,col)

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • analysis-model
    • Jenkins 2.319.1
      Warnings Next Generation Plugin 9.9.0
      Analysis Model API Plugin 10.8.0

      Microsoft's C# compiler can report a warning like this via MSBuild:

      C:\Projects\EndLocation\Program.cs(5,24,5,26): warning CS1584: XML comment has syntactically incorrect cref attribute 'No such thing' [C:\Projects\EndLocation\EndLocation.csproj]
      

      The numbers between the parentheses are the starting line, starting column, ending line, and ending column. See MSBuild / Visual Studio aware error messages and message formats. Analysis-core is not yet able to parse this four-number format.

      Demo for how to get a warning in this format

      EndLocation.csproj:

      <Project Sdk="Microsoft.NET.Sdk">
      
        <PropertyGroup>
          <OutputType>Exe</OutputType>
          <TargetFramework>net6.0</TargetFramework>
          <GenerateDocumentationFile>true</GenerateDocumentationFile>
          <ErrorEndLocation>true</ErrorEndLocation>
        </PropertyGroup>
      
      </Project>
      

      Program.cs:

      namespace EndLocation
      {
          class Program
          {
              /// <see cref="No such thing"/>
              static void Main()
              {
              }
          }
      }
      

      Compilation with .NET SDK 6.0.100:

      $ dotnet build
      Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
      Copyright (C) Microsoft Corporation. All rights reserved.
      
        Determining projects to restore...
        All projects are up-to-date for restore.
      C:\Projects\EndLocation\Program.cs(5,24,5,26): warning CS1584: XML comment has syntactically incorrect cref attribute 'No such thing' [C:\Projects\EndLocation\EndLocation.csproj]
        EndLocation -> C:\Projects\EndLocation\bin\Debug\net6.0\EndLocation.dll
      
      Build succeeded.
      
      C:\Projects\EndLocation\Program.cs(5,24,5,26): warning CS1584: XML comment has syntactically incorrect cref attribute 'No such thing' [C:\Projects\EndLocation\EndLocation.csproj]
          1 Warning(s)
          0 Error(s)
      
      Time Elapsed 00:00:02.19
      

          [JENKINS-67291] Parse MSBuild-compatible diagnostic with (line,col,line,col)

          Kalle Niemitalo created issue -
          Kalle Niemitalo made changes -
          Description Original: Microsoft's C# compiler can report a warning like this via MSBuild:

          {code:none}
          C:\Projects\EndLocation\Program.cs(5,24,5,26): warning CS1584: XML comment has syntactically incorrect cref attribute 'No such thing' [C:\Projects\EndLocation\EndLocation.csproj]
          {code}

          The numbers between the parentheses are the starting line, starting column, ending line, and ending column. See [MSBuild / Visual Studio aware error messages and message formats|https://docs.microsoft.com/en-us/archive/blogs/msbuild/msbuild-visual-studio-aware-error-messages-and-message-formats]. Analysis-core is not yet able to parse this four-number format.

          h2. Demo for how to get a warning in this format

          EndLocation.csproj:

          {code:xml}
          <Project Sdk="Microsoft.NET.Sdk">

            <PropertyGroup>
              <OutputType>Exe</OutputType>
              <TargetFramework>net6.0</TargetFramework>
              <GenerateDocumentationFile>true</GenerateDocumentationFile>
              <ErrorEndLocation>true</ErrorEndLocation>
            </PropertyGroup>

          </Project>
          {code}

          Program.cs:

          {code:C#}
          namespace EndLocation
          {
              class Program
              {
                  /// <see cref="No such thing"/>
                  static void Main()
                  {
                  }
              }
          }
          {code}

          Compilation with .NET SDK 6.0.100:

          {noformat}
          $ dotnet build
          Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
          Copyright (C) Microsoft Corporation. All rights reserved.

            Determining projects to restore...
            All projects are up-to-date for restore.
          C:\Projects\EndLocation\Program.cs(5,24,5,26): warning CS1584: XML comment has syntactically incorrect cref attribute 'No such thing' [C:\Projects\EndLocation\EndLocation.csproj]
            EndLocation -> C:\Projects\EndLocation\bin\Debug\net6.0\EndLocation.dll

          Build succeeded.

          C:\Projects\EndLocation\Program.cs(5,24,5,26): warning CS1584: XML comment has syntactically incorrect cref attribute 'No such thing' [C:\Projects\EndLocation\EndLocation.csproj]
              1 Warning(s)
              0 Error(s)

          Time Elapsed 00:00:02.19
          {code}
          New: Microsoft's C# compiler can report a warning like this via MSBuild:

          {code:none}
          C:\Projects\EndLocation\Program.cs(5,24,5,26): warning CS1584: XML comment has syntactically incorrect cref attribute 'No such thing' [C:\Projects\EndLocation\EndLocation.csproj]
          {code}

          The numbers between the parentheses are the starting line, starting column, ending line, and ending column. See [MSBuild / Visual Studio aware error messages and message formats|https://docs.microsoft.com/en-us/archive/blogs/msbuild/msbuild-visual-studio-aware-error-messages-and-message-formats]. Analysis-core is not yet able to parse this four-number format.

          h2. Demo for how to get a warning in this format

          EndLocation.csproj:

          {code:xml}
          <Project Sdk="Microsoft.NET.Sdk">

            <PropertyGroup>
              <OutputType>Exe</OutputType>
              <TargetFramework>net6.0</TargetFramework>
              <GenerateDocumentationFile>true</GenerateDocumentationFile>
              <ErrorEndLocation>true</ErrorEndLocation>
            </PropertyGroup>

          </Project>
          {code}

          Program.cs:

          {code:C#}
          namespace EndLocation
          {
              class Program
              {
                  /// <see cref="No such thing"/>
                  static void Main()
                  {
                  }
              }
          }
          {code}

          Compilation with .NET SDK 6.0.100:

          {noformat}
          $ dotnet build
          Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
          Copyright (C) Microsoft Corporation. All rights reserved.

            Determining projects to restore...
            All projects are up-to-date for restore.
          C:\Projects\EndLocation\Program.cs(5,24,5,26): warning CS1584: XML comment has syntactically incorrect cref attribute 'No such thing' [C:\Projects\EndLocation\EndLocation.csproj]
            EndLocation -> C:\Projects\EndLocation\bin\Debug\net6.0\EndLocation.dll

          Build succeeded.

          C:\Projects\EndLocation\Program.cs(5,24,5,26): warning CS1584: XML comment has syntactically incorrect cref attribute 'No such thing' [C:\Projects\EndLocation\EndLocation.csproj]
              1 Warning(s)
              0 Error(s)

          Time Elapsed 00:00:02.19
          {noformat}

          I suppose the fix would go in https://github.com/jenkinsci/analysis-model/blob/v10.8.0/src/main/java/edu/hm/hafner/analysis/parser/MsBuildParser.java, but the regex pattern looks rather complex.

          More references for MSBuild diagnostic formats:

          Kalle Niemitalo added a comment - I suppose the fix would go in https://github.com/jenkinsci/analysis-model/blob/v10.8.0/src/main/java/edu/hm/hafner/analysis/parser/MsBuildParser.java , but the regex pattern looks rather complex. More references for MSBuild diagnostic formats: CanonicalError.cs parses a diagnostic of a tool, for processing within MSBuild. EventArgsFormatting.cs formats a diagnostic back to a string. This can also use the (line-line,col) format that was not mentioned in MSBuild / Visual Studio aware error messages and message formats .

          So the whole set of location formats is:

          • (line)
          • (line,column)
          • (line-endLine)
          • (line,column-endColumn)
          • (line-endLine,column)
          • (line,column,endLine,endColumn)

          MsBuildParser is currently able to parse the first two.

          Kalle Niemitalo added a comment - So the whole set of location formats is: (line) (line,column) (line-endLine) (line,column-endColumn) (line-endLine,column) (line,column,endLine,endColumn) MsBuildParser is currently able to parse the first two.

          Ulli Hafner added a comment -

          Hopefully, we sometimes get a volunteer to provide support for Sarif in the analysis-model project then we are not required to use this complex regexp anymore.

          Ulli Hafner added a comment - Hopefully, we sometimes get a volunteer to provide support for Sarif in the analysis-model project then we are not required to use this complex regexp anymore.
          Ulli Hafner made changes -
          Assignee Original: Ulli Hafner [ drulli ]
          Labels New: help-wanted newbie-friendly

          The Roslyn C# compiler can write diagnostics to a file in SARIF formats, but if there are problems with NuGet package dependencies or such, then the diagnostics do not come from the C# compiler and cannot take advantage of that feature. So you'd likely need the regexp anyway, unless the build is using a custom MSBuild logger that writes SARIF.

          Kalle Niemitalo added a comment - The Roslyn C# compiler can write diagnostics to a file in SARIF formats, but if there are problems with NuGet package dependencies or such, then the diagnostics do not come from the C# compiler and cannot take advantage of that feature. So you'd likely need the regexp anyway, unless the build is using a custom MSBuild logger that writes SARIF.

          MS_BUILD_WARNING_PATTERN could perhaps be simplified if it only tried to recognize diagnostics emitted by MSBuild console loggers or file loggers. Why does it involve ANT_TASK; is that for scenarios where Ant runs MSBuild and further decorates its output?

          Kalle Niemitalo added a comment - MS_BUILD_WARNING_PATTERN could perhaps be simplified if it only tried to recognize diagnostics emitted by MSBuild console loggers or file loggers. Why does it involve ANT_TASK; is that for scenarios where Ant runs MSBuild and further decorates its output?

            Unassigned Unassigned
            kon Kalle Niemitalo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: