Support for StyleCop Report

gep13's Avatar

gep13

22 Sep, 2014 12:31 PM

Hello,

I am trying to run StyleCop as part of my build process, and I would like to see the report in the build results.

I have tried to do this, but I am running into an issue. My results file doesn't seem to be there where I expect it to be. It is almost as though StyleCop isn't being executed. The only reason that this wouldn't happen is if the nuget package for StyleCop.Msbuild wasn't available. And I think that this is at the heart of the matter.

In each build that I have executed since I started trying to do this, I am getting the following output when I try to do a nuget package restore:

All packages listed in packages.config are already installed.

https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0....
https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0....
https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0....
https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0....

When I would expect to get:

Running NugetPackageRestore...
Installing 'StyleCop.MSBuild 4.7.49.0'.
Successfully installed 'StyleCop.MSBuild 4.7.49.0'.
All packages listed in packages.config are already installed.

Which is what I get if I run the build locally, but first delete the StyleCop.Msbuild folder from the packages folder. The reason that I started looking at this as the potential problem is that I am using build_cache, and I wondered if that might be an issue.

Also, what support is there for transforming the XML file from the report file into something that can be easily read in the results window?

Thanks
Gary

  1. 1 Posted by gep13 on 22 Sep, 2014 12:45 PM

    gep13's Avatar

    To rule out the build cache, I have just pushed a change to the appveyor.yml file to remove it, and I can see the nuget packages getting restored:

    https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/1....

    Here there are:

    Running NugetPackageRestore... 
    Installing 'Autofac 3.5.2'.
    Installing 'Microsoft.Bcl.Build 1.0.21'.
    Installing 'AutoMapper 3.2.1'.
    Installing 'Microsoft.Data.OData 5.6.2'.
    Successfully installed 'Autofac 3.5.2'.
    Successfully installed 'Microsoft.Bcl.Build 1.0.21'.
    Successfully installed 'Microsoft.Data.OData 5.6.2'.
    Installing 'Rx-Core 2.2.5'.
    Istalling 'Mindscape.Raygun4Net 3.3.2'.
    Successfully installed 'AutoMapper 3.2.1'.
    Successfully installed 'Rx-Core 2.2.5'.
    Successfully installed 'Mindscape.Raygun4Net 3.3.2'.
    Installing 'Newtonsoft.Json 6.0.5'.
    Successfully installed 'Newtonsoft.Json 6.0.5'.
    Installing 'log4net 2.0.3'.
    Installing 'Rx-Main 2.2.5'.
    Installing 'Rx-WPF 2.2.5'.
    Installing 'Rx-PlatformServices 2.2.5'.
    Installing 'Microsoft.Bcl 1.1.9'.
    Installing 'Microsoft.Bcl.Async 1.0.168'.
    Installing 'Microsoft.Data.Edm 5.6.2'.
    Installing 'MahApps.Metro 0.14.0.0'.
    Installing 'MahApps.Metro.Resources 0.3.0.0'.
    Successfully installed 'Rx-Main 2.2.5'.
    Installing 'Rx-Xaml 2.2.5'.
    Successfully installed 'Rx-WPF 2.2.5'.
    Successfully installed 'Rx-Xaml 2.2.5'.
    Successfully installed 'MahApps.Metro 0.14.0.0'.
    Successfully installed 'Rx-PlatformServices 2.2.5'.
    Successfully installed 'log4net 2.0.3'.
    Installing 'System.Spatial 5.6.2'.
    Successfully installed 'MahApps.Metro.Resources 0.3.0.0'.
    Successfully installed 'Microsoft.Data.Edm 5.6.2'.
    Installing 'Rx-Linq 2.2.5'.
    Successfully installed 'System.Spatial 5.6.2'.
    Installing 'Microsoft.Data.Services.Client 5.6.2'.
    nstalling 'System.Management.Automation 6.1.7601.17515'.
    Installing 'Rx-Interfaces 2.2.5'.
    Successfully installed 'Rx-Interfaces 2.2.5'.
    Successfully installed 'System.Management.Automation 6.1.7601.17515'.
    Successfully installed 'Microsoft.Bcl.Async 1.0.168'.
    Successfully installed 'Rx-Linq 2.2.5'.
    Successfully installed 'Microsoft.Data.Services.Client 5.6.2'.
    Successfully installed 'Microsoft.Bcl 1.1.9'.
    

    As you can see, StyleCop.MsBuild is not on the list of packages that were installed, even though it is part of the packages.config file that I am checking in.

    I have just done:

    git clone -q https://github.com/chocolatey/ChocolateyGUI.git C:\projects\ChocolateyGUI
    git fetch -q origin +refs/pull/164/merge:
    git checkout -qf FETCH_HEAD
    

    On my local machine, and these are the contents of the packages.config file:

    <?xml version="1.0" encoding="utf-8"?>
    <packages>
      <package id="Autofac" version="3.5.2" targetFramework="net40" />
      <package id="AutoMapper" version="3.2.1" targetFramework="net40" />
      <package id="log4net" version="2.0.3" targetFramework="net40" />
      <package id="MahApps.Metro" version="0.14.0.0" targetFramework="net40" />
      <package id="MahApps.Metro.Resources" version="0.3.0.0" targetFramework="net40" />
      <package id="Microsoft.Bcl" version="1.1.9" targetFramework="net40" />
      <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
      <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net40" />
      <package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net40" />
      <package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net40" />
      <package id="Microsoft.Data.Services.Client" version="5.6.2" targetFramework="net40" />
      <package id="Mindscape.Raygun4Net" version="3.3.2" targetFramework="net40" />
      <package id="Newtonsoft.Json" version="6.0.5" targetFramework="net40" />
      <package id="Rx-Core" version="2.2.5" targetFramework="net40" />
      <package id="Rx-Interfaces" version="2.2.5" targetFramework="net40" />
      <package id="Rx-Linq" version="2.2.5" targetFramework="net40" />
      <package id="Rx-Main" version="2.2.5" targetFramework="net40" />
      <package id="Rx-PlatformServices" version="2.2.5" targetFramework="net40" />
      <package id="Rx-WPF" version="2.2.5" targetFramework="net40" />
      <package id="Rx-Xaml" version="2.2.5" targetFramework="net40" />
      <package id="StyleCop.MSBuild" version="4.7.49.0" targetFramework="net40" developmentDependency="true" />
      <package id="System.Management.Automation" version="6.1.7601.17515" targetFramework="net40" />
      <package id="System.Spatial" version="5.6.2" targetFramework="net40" />
    </packages>
    
  2. 2 Posted by gep13 on 22 Sep, 2014 12:46 PM

    gep13's Avatar

    Sorry, that submitted before I was finished...

    Do you have any ideas as to why the StyleCop.MsBuild package isn't getting installed? I have just noticed the developmentDependency flag, but my understanding of that is that it only gets inspected during nuget pack not nuget restore

    Any ideas?

    Thanks

    Gary

  3. 3 Posted by gep13 on 23 Sep, 2014 06:51 AM

    gep13's Avatar

    Hello Feodor,

    I am really starting to think that there is something not quite right with the Pull Request mechanism in AppVeyor, or the way that I am doing things.

    I have just merged the above work into the develop branch, and straight away, where the StyleCop.MsBuild package was not getting installed, now it is:

    https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/1....

    Do you have any ideas about what could be going on here.

    This is the second time that code, while in a Pull Request branch, wasn't working correctly, but as soon as I pull it into the main branch, it works exactly as expected.

    Thanks

    Gary

  4. 4 Posted by gep13 on 23 Sep, 2014 09:06 PM

    gep13's Avatar

    Ok, as discussed on GitHub, I don't think this issue is anything to do with AppVeyor, but rather GitVersion, so don't think there is anything else to worry about on that score.

    However, I would still like to know how I can submit other result xml files to AppVeyor for display in the build report.

    The two main tests are StyleCop and also Code Analysis (FxCop). How can I go about including these test results? I am assuming that this would be something that would have to be done on your end?

    Thanks

    Gary

  5. Support Staff 5 Posted by Feodor Fitsner on 23 Sep, 2014 09:25 PM

    Feodor Fitsner's Avatar

    Wow, amazing findings! I've been sure GitVersion works in kind of "read-only" mode. Interesting indeed.

    For pushing test results into AppVeyor there are two ways right now:

    1. Using Build Worker REST (PS, CMD) API, so you have an additional PS script parsing XML and calling API for each test or batch. This sample is a good start: http://help.appveyor.com/discussions/questions/495-integrating-chut...
    2. Uploading test results to AppVeyor. xUnit, NUnit and MSTest formats are supported.

    Though I think other parsers could be easily added. Send me their sample XML output.

  6. 6 Posted by gep13 on 24 Sep, 2014 11:52 AM

    gep13's Avatar

    Sure, no probs. Here are some sample reports, both for StyleCop and FxCop, for when there are errors, and when there are none.

    In the mean time, I will take a look at the REST API.

    However, I do think that this is something that would benefit multiple people, and a common usage, so direct support from a parser in AppVeyor would be a great addition :-)

    Thanks!

  7. 7 Posted by gep13 on 07 Oct, 2014 12:19 PM

    gep13's Avatar

    Feodor,

    How do this look to you?

    https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0....

    I have added a very simple parsing routine to my psake script to inspect the violations within the generated StyleCop Report:

    function analyseStyleCopResults( [Parameter(ValueFromPipeline=$true)]$styleCopResultsFile ) {
      $styleCopViolations = [xml](Get-Content $styleCopResultsFile)
      
      foreach ($styleCopViolation in $styleCopViolations.StyleCopViolations.Violation) {
        $output = "Violation of Rule $($styleCopViolation.RuleId): $($styleCopViolation.Rule) Line Number: $($styleCopViolation.LineNumber) -Outcome Failed -FileName $($styleCopViolation.Source) -ErrorMessage $($styleCopViolation.InnerXml)"
        Write-Host $output
        
        if(isAppVeyor) {
          Add-AppveyorTest "Violation of Rule $($styleCopViolation.RuleId): $($styleCopViolation.Rule) Line Number: $($styleCopViolation.LineNumber)" -Outcome Failed -FileName $styleCopViolation.Source -ErrorMessage $styleCopViolation.InnerXml
        }
      }
    }
    

    Gary

  8. 8 Posted by gep13 on 07 Oct, 2014 12:20 PM

    gep13's Avatar

    Next up, Code Analysis Results file...

  9. Support Staff 9 Posted by Feodor Fitsner on 07 Oct, 2014 06:38 PM

    Feodor Fitsner's Avatar

    Looks cool! I'm moving this thread to KB.

  10. 10 Posted by gep13 on 08 Oct, 2014 09:25 PM

    gep13's Avatar

    Sounds good to me.

    Should I close this discussion, or leave it open?

  11. Support Staff 11 Posted by Feodor Fitsner on 08 Oct, 2014 09:34 PM

    Feodor Fitsner's Avatar

    Leave it open.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac