Danny
Danny

Reputation: 826

Visual Studio 2015 Code Analysis with StyleCop Analyzers

I am using Visual Studio 2015 with Code Analysis with the NuGet package StyleCop analyzers. When I run code Analysis I also get warnings about auto generated code from classes generated by entity framework or added service references.

The headers of my generated files contain

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

or

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

In my project I have the option "Suppress results from generated code" enabled

How can I exclude my generated code from code analysis?

Upvotes: 1

Views: 345

Answers (1)

Danny
Danny

Reputation: 826

Following the comment of Hans Passant I added the following attribute to my generated classes by changing the text template of my entity framework model

[GeneratedCode("EntityModelCodeGenerator", "6.1.3")]

public partial class .... { }

The classes are now skipped by code analysis

Upvotes: 1

Related Questions