问题
I am trying to port everything from Entity Framework 6.3 to Entity Framework Core 2.1.2 and this is my first experience with EF Core. I have 2 projects one is my core or infrastructure project with all the entity models, DB Context and repositories and the other one is an asp.Net MVC which is my startup project and using all the services from the core project. Both projects are using .NetStandard Library 2.0.3 and targeted .Net Framework 4.6.2. And I have .Net Core SDK 2.2 on my machine.
The problem:
1- Converted everything to Entity Framework Core (All the entity mappings, contexts and repositories) and all the stuff seems fine, both projects build successfully.
2- starting first migration targeting existing database and entity models. Now while the migration process building both projects I am getting a strange error on asp.net MVC project as following:
An instance of analyzer Microsoft.EntityFrameworkCore.RawSqlStringInjectionDiagnosticAnalyzer cannot be created from C:\Users\user\.nuget\packages\microsoft.entityframeworkcore.analyzers\2.1.2\analyzers\dotnet\cs\Microsoft.EntityFrameworkCore.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
3- Now everytime you build the Asp.net project, you get the same error.
I really have no idea about this RawSqlStringInjectionDiagnosticAnalyzer and why this being even used by the projects, I have spent 2 days so far on this problem search all over the Internet, some people experienced somewhat similar problems (like this one) but could not found any solution, some of the stuff that I did was:
- Updated my VS to the latest version (15.9.7), no luck
- Tried to reference different versions of EF Core including Analyzer for both projects, no luck
- I know Microsoft.CodeAnalysis dll should be a VS internal mechanism, nevertheless tried to reference it manually, no luck
- Tried to include Microsoft.CodeAnalysis nuget package, no luck
- Also there were other packages that I have tried, couldn't remember the names now, no luck
Please help me I am tired of adding and referencing different packages and binaries, I can't even grasp the problem.
回答1:
I have realized this should be a warning and not an error so I found out that the "Treat warning as error" options in the project settings is enabled so that's reasons I am getting this as an error, however, still do not know the reason behind this warning.
来源:https://stackoverflow.com/questions/54900962/ef-core-analyzer-rawsqlstringinjectiondiagnosticanalyzer-error