从roslyn分析器中排除文件

时间:2015-06-26 09:16:45

标签: roslyn analyzer

由于我们有很多生成的代码,一些roslyn分析器对此代码感到疯狂。有没有办法从分析仪中排除一些文件?

1 个答案:

答案 0 :(得分:10)

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