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?
Asked
Active
Viewed 2,862 times
1 Answers
12
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

JoshVarty
- 9,066
- 4
- 52
- 80
-
3this means that only generated files with this pattern get's excluded. It would be nice if we could exclude any files like resharper does. Furthermore it would be interesting to have a attribute, like the [ExcludeFromCodeAnalysis] to skip analysis. – Mantzas Jun 26 '15 at 12:43
-
3Just opened a issue in github's roslyn repository. #3705 – Mantzas Jun 26 '15 at 12:52