StyleCop Doesnt Ignore Generated Code attribute?

Jul 21, 2011 at 8:00 PM

I have some code that was created by the XSD tool.

It marks the created classes with the following attribute:

  [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd""2.0.50727.3038")]

Is there a way to have StyleCop pay attention to this attribute and ignore checking the file contents?  I noticed that the WinForms Designer files have a similiar attribute as well that is apparently ignored.

Developer
Jul 26, 2011 at 7:55 PM

Hi John,

WinForms designer files are ignored because of their extension.

Auto-generated files are always skipped if contain <auto-generated> tag in file header.

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.225
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

You could just add the tag to your file and it will be ignored.

P.S. In future there will be probably some changes in this behaviour, but now it works as I described.

Best regards,
Oleg Shuruev 

 

Jul 28, 2011 at 6:30 PM

The file has this as its start...  You are saying that I need to move the header in the autogenerated file to the top?

 

using System;
using System.Collections.Generic;
using System.Text;
 
using System.Xml.Serialization;
 
namespace XPedient.Interop.LiveScan.Common
{
  //------------------------------------------------------------------------------
  // <auto-generated>
  //     This code was generated by a tool.
  //     Runtime Version:2.0.50727.3053
  //
  //     Changes to this file may cause incorrect behavior and will be lost if
  //     the code is regenerated.
  // </auto-generated>
  //------------------------------------------------------------------------------
 
  // 
  // This source code was auto-generated by xsd, Version=2.0.50727.3038.
  // 
 
 
  /// <remarks/>
  [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd""2.0.50727.3038")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
  [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
  public partial class ROOT
Developer
Jul 29, 2011 at 6:24 AM

Yeah, I guess currently skipping would work if <auto-generated> were placed before "namespace", not after.

Best regards,
Oleg Shuruev

Jul 24, 2012 at 3:31 PM

Side note... looks like any linebreak after the header followed by auto-generated tag causes stylecop to not conform to auto generated policy

// --------------------------------------------------------------------------------------------------------------------
// <copyright file="xx.cs" company="xx, Inc.">
//   Copyright � 2000 - 2012 xx, Inc.  All rights reserved.
// </copyright>
// <summary>
//   summary goes here
// </summary>
// ------------------------------------------------------------------------------

// <auto-generated>
// Generated by Xsd2Code. Version 3.5.2.0
// </auto-generated>

Removing the linebreak causes everything to work as expected.