Export <auto-generated /> code documentation element to generated code files
We are using StyleCop.Analyzers extensively to ensure a unique coding style in our projects.
The problem is, we receive a lot of warnings about coding style rule violations in code files generated from EntityDeveloper's DbContext
code generation template.
Some of the warnings can be easily suppressed by activating the DbContext template's property "Generate GeneratedCode Attribute" .
But some disturbing warnings remain (e.g. SA1027, SA1200, SA1210 especially in generated enum code files or pregenerated views).
These warnings can be suppress using global suppression file. But unfortunately only for all code files in the particular project, instead of only for the affected generated code files.
DbContext code generated template could easily solve this issue, if it exports <auto-generated /> XML-Documentation element as header in each generated file.
Currently this code comment header is exported each generated file:
//------------------------------------------------------------------------------
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Devart Entity Developer tool using Entity Framework DbContext template.
// ...
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//------------------------------------------------------------------------------
If this code comment is changed to use the <auto-generated /> XML-Documentation element:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by Devart Entity Developer tool using Entity Framework DbContext template.
// ...
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
the complete file is excluded from coding style analyzers.
The <auto-generated /> XML-Documentation element seems not to be a special StyleCop feature e.g. ResXFileCodeGenerator from Microsoft generates such comments
in typed resource code files, too.
e.g. code header comment from a Resx.Designer file:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
There are some discussion about how to exclude code files from roslyn based code analyzers.
Currently using the <auto-generated /> XML-Documentation element seems to be the only working approach.
see also
https://github.com/dotnet/roslyn/issues/3705
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/726
https://github.com/DotNetAnalyzers/StyleCopAnalyzers