entity-framework-5 - EF Code First 迁移导致 CA1701 和 CA1703

标签 entity-framework-5 code-analysis resx entity-framework-migrations

在为我的代码优先 EF 5 上下文启用迁移后,由于迁移历史字符串被添加到项目的 resx 文件中,我开始收到大量 CA1701 和 CA1703 代码分析违规。

我不在乎禁用 CA1701 和 CA1703,也不想为将要添加的每个单独迁移抑制 100ish 消息。有没有办法将 resx 的 xml 文件或单个 resx 条目标记为// 以便停止发生?如果我必须禁用这两个规则,那么就这样吧,希望这不是唯一合理的答案!

TIA
杰森

最佳答案

我自己今天才注意到这一点。您可以在您的 AssemblyInfo.cs 或 GlobalSuppressions.cs 文件中使用以下内容在资源级别抑制 CA1701 和 CA1703 警告:

[assembly: SuppressMessage("Microsoft.Naming",
    "CA1701:ResourceStringCompoundWordsShouldBeCasedCorrectly",
    Justification = "The auto-genererated code from code first migrations trigger this warning.",
    Scope = "resource", Target = "Full.Namespace.To.Your.Migrations.NameOfYourMigration.resources")]
[assembly: SuppressMessage("Microsoft.Naming",
    "CA1703:ResourceStringsShouldBeSpelledCorrectly",
    Justification = "The auto-genererated code from code first migrations trigger this warning.",
    Scope = "resource", Target = "Full.Namespace.To.Your.Migrations.NameOfYourMigration.resources")]

您需要为每个迁移执行此操作,但这比单独抑制每个警告要好得多。

关于entity-framework-5 - EF Code First 迁移导致 CA1701 和 CA1703,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18363665/

相关文章:

c# - DB ConnectionState = Open 但 context.SaveChanges 抛出 "connection broken"异常

c# - Entity Framework 无法导入执行 FTS 的存储过程

c# - 代码分析在设计器代码中发现 CA2213 错误

c# - 如何从C#的项目资源文件夹中存储的音频文件中提取文件路径

c# - 如何覆盖 Entity Framework 中对象的保存行为

c# - EntityFramework 中的 ObjectDisposedException

sql - 将可为 Null 的列传递给函数会导致警告 SR0007 - 即使函数内部使用 COALESCE 和 ISNULL

c# - 如何从 System.Drawing.Bitmap 对象中提取原始图像流?

xaml - 在 XAML 中将 RESX 与 Windows Phone 7 一起使用