Roslyn: Compiler warnings (Like CS8019) triggers on generated code

Created on 11 Sep 2015  路  5Comments  路  Source: dotnet/roslyn

I'm trying to enable all possible warnings as error by default but CS8019 can't be enabled due to generated code that can't be ignored :( (My example is CS8019 but i'm sure that i'll find a few more as none of the compiler warnings seem to check for generated code)

It's can even be enabled as a warning as otherwise it flood the error list with non-actionable lines.

For example GenerateTargetFrameworkMonikerAttribute generated files trigger it :

C:\Users\jroncagl\AppData\Local\Temp\.NETFramework,Version=v4.5.1.AssemblyAttributes.cs(2,1)
: warning CS8019: Unnecessary using directive. [c:\Code\test.csproj]

But winforms *.Designer.cs or WPF *.g.cs files also generate it.

The warning is generated in CSharpCompilation.cs method ReportUnusedImports.

Suggestion

I would suggest that the compiler (And IDE as the analyzers also run here) exclude by default generated files (With a documentation of how this distinction is made) from all warning and errors that wouldn't fail the build (Coming from analyzers or from the compiler provided diagnostics).

Related

This issue is related to a few others :

  • _Exclude files or folder from running through the analyzers_ #3705 : It would be an ugly hack to have to use manual ignores for files generated in temp folder, and even if it would work for *.Designer.cs files it would mean that every .NET developer need to copy paste the same ignores in all projects.
  • _Light bulb code fix doesn't work on generated files_ #2753 : Is a related issue where the FixAllProvider patched this problem after the fact and created discrepencies
  • _Expose a public API to tell whether Document/SyntaxTree is likely a generated file_ #4530 : As the analyzer runner doesn't handle it all analyzers need to duplicate the code handling it.

Note: IDE0005 is a little bit better as it seem to ignore WPF generated files due to <auto-generated> markers, but still doesn't ignore .NETFramework,Version=v4.5.1.AssemblyAttributes.cs or *.Designer.cs.

Area-Analyzers

Most helpful comment

Is there any known workaround regarding that issue (with VS 2015 - Update2)?

All 5 comments

We will track the work for this in #3705. I will add a note to #3705 noting your feedback on the solutions proposed in that issue.

Is there any known workaround regarding that issue (with VS 2015 - Update2)?

This is a solid workaround: http://stackoverflow.com/a/35553079/1108891

This Workaround is only applicable to the AssemblyAttributes.cs file. It is not working for .g.cs files in general. So, still there is a need for ignoring These files.

Related to #24976 and thus still an issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OndrejPetrzilka picture OndrejPetrzilka  路  3Comments

codingonHP picture codingonHP  路  3Comments

glennblock picture glennblock  路  3Comments

marler8997 picture marler8997  路  3Comments

ashmind picture ashmind  路  3Comments