-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code generated by dotnet ef dbcontext scaffold
should be marked as auto-generated
#28180
Comments
Adding the `<auto-generated/>` tag prevents analyzers to generate spurious warnings. Fixes dotnet#28180
Duplicate of #23514 |
Thanks Arthur, that's good to know. I think it would be better if I'm a bit disappointed that #28181 was not merged, it looked like a really quick win to me, literally a 6 lines change (ignoring the tests) that would benefit everyone for a good experience out of the box. I just came across this code I wrote some time ago to workaround this issue. 😕 private static void AddAutogeneratedComment(DirectoryInfo directory)
{
Parallel.ForEach(directory.GetFiles("*.cs"), file =>
{
var lines = new[]
{
"// <auto-generated />",
"#nullable enable",
"",
}.Concat(File.ReadAllLines(file.FullName));
File.WriteAllLines(file.FullName, lines);
});
} |
Running
dotnet ef dbcontext scaffold
generates code which often produces analyzer warnings, e.g. using directive that can be removed, virtual member call in constructor, auto-property accessor never used, etc.Adding an
<auto-generated/>
comment in the generated code would instruct the analyzers to ignore those warnings. See https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-options#exclude-generated-code and dotnet/roslyn#3705The text was updated successfully, but these errors were encountered: