Excluir el archivo del análisis de Stylecop: la etiqueta "generada automática" se ignora

StackOverflow https://stackoverflow.com/questions/5027889

  •  14-11-2019
  •  | 
  •  

Pregunta

Al principio de un archivo C #, he agregado:

//-----------------------------------------------------------------------
// <copyright company="SomeCompany" file="MyFile.cs">
// Copyright © Some Company, 2011
// </copyright>
// <auto-generated />
//-----------------------------------------------------------------------

Quiero que StyleCop se salte revisando este archivo, así que utilicé el truco de auto-generated explicado en Otras respuestas .

Sin embargo, después de limpiar y reconstruir mi solución, Stylecop sigue generando advertencias para este archivo.¿Por qué pasó esto?¿Cómo puede ser arreglado?

Estoy usando Microsoft Visual Studio 2008 Professional Edition y Stylecop v4.3.

¿Fue útil?

Solución

@Frédéric - unfortunately, Analyze generated files option is not somehow connected with skipping files with <auto-generated /> tag.

Files containing <auto-generated /> text will always be skipped regardless the value of the setting.

@Daniel - I believe that you deal with a bug in version 4.3 which was released more than a year ago and is definitely obsolete now. The only reason to use 4.3 is only if you use Visual Studio 2005, which is not supported by StyleCop 4.4.

I strongly recommend you upgrading to 4.4 - I've just checked your example and it works fine.

Otros consejos

You can set file exclusions within the Settings.StyleCop file. The file is located in to your solution / project or in your StyleCop install directory.

You can then use regex within the Parser settings to define files you want to ignore

<Parsers>
  <Parser ParserId="Microsoft.StyleCop.CSharp.CsParser">
    <ParserSettings>
      <BooleanProperty Name="AnalyzeDesignerFiles">False</BooleanProperty>
      <CollectionProperty Name="GeneratedFileFilters">
        <Value>\.g\.cs$</Value>
        <Value>\.generated\.cs$</Value>
        <Value>\.g\.i\.cs$</Value>
        <Value>codegen.*\.cs$</Value>
      </CollectionProperty>
    </ParserSettings>
  </Parser>
</Parsers>

In this case I want to ignore codegen.whatever.cs

Check StyleCop documentation. My favourite is <auto-generated /> tag on the top of the document or you can use #region directive or other options mentioned in the docs.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top