This project is read-only.

StyleCop Doesnt Ignore Generated Code attribute?

Jul 21, 2011 at 9:00 PM

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

It marks the created classes with the following attribute:


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.

Jul 26, 2011 at 8: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 7: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.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
  [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
  public partial class ROOT
Jul 29, 2011 at 7: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 4: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
// </auto-generated>

Removing the linebreak causes everything to work as expected.