Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding a file from the roslyn analyzers

Since we have a lot of generated code, some roslyn analyzers go crazy about this code. Is there any way to exclude some files from analyzers?

like image 327
Mantzas Avatar asked Jun 26 '15 09:06

Mantzas


Video Answer


1 Answers

There is currently no way to explicitly say "don't run my analyzer on generated code". You have to handle this manually.

I believe the heuristics used are as follows. (I took this list from Giovanni Bassi, one of the authors of Code Cracker) A file is auto generated if any of the following conditions are met:

It has one of these attributes:

  • DebuggerNonUserCodeAttribute
  • GeneratedCodeAttribute

The file path contains:

  • *.g.cs
  • *.designer.cs
  • *.AssemblyInfo.cs
  • *.generated.cs
  • *.g.cs
  • *.g.i.cs
  • *.AssemblyAttributes.cs
  • TemporaryGeneratedFile_*.cs

A header comment contains:

  • <auto-generated>

The Code Cracker project has a number of extension methods for detecting generated files. Check out GeneratedCodeAnalysisExtensions

like image 97
JoshVarty Avatar answered Nov 08 '22 14:11

JoshVarty