Search code examples
entity-framework-5code-analysisresxentity-framework-migrations

EF Code First Migrations causing CA1701 and CA1703


Upon enabling migrations for my code-first EF 5 context I started to receive a TON of CA1701 and CA1703 code analysis violations due to the migration history string being added to the project's resx file.

I do not care to disable CA1701 and CA1703 and also do not want to suppress 100ish messages for each individual migration that's going to be added. Is there a way to mark a resx's xml file or individual resx entry as // <auto-generated /> so this stops happening? If I have to disable the two rules, then so be it just hoping that's not the only sane answer!

TIA Jason


Solution

  • I just noticed this today, myself. You can suppress the CA1701 and CA1703 warnings at the resource level with the following in either your AssemblyInfo.cs or a GlobalSuppressions.cs file:

    [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")]
    

    You'll need to do this for each of your migrations, but it's much better than suppressing each warning individually.