Why adding a model Entity Framework to csproj fail?

csproj entity-framework-6

Question

Here is my project file csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
     <TargetFramework>net4.6</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
     <PackageReference Include="EntityFramework" Version="6.2.0" />
  </ItemGroup>
</Project>

In VisualStudio 2017 I try to add item "ADO.NET Entity Data Model". When push the Add button VS throw me an exception...

Exception

In the log file I got this :

===================== 2018-02-21 15:23:47 Recoverable System.Reflection.TargetInvocationException: An exception was raised by the target of a call. ---> Microsoft.VisualStudio.ProjectSystem.ProjectException: The item type 'EntityDeploy' is not supported by this project item provider. at Microsoft.VisualStudio.ProjectSystem.ProjectErrorUtilities.ThrowProjectExceptionHelper(Exception innerException, String unformattedMessage, Object[] args) at Microsoft.VisualStudio.ProjectSystem.ProjectErrorUtilities.ThrowProjectException(String message, Object arg0) à Microsoft.VisualStudio.ProjectSystem.CpsProjectItem`1.d__25.MoveNext()

1
6
2/21/2018 8:55:39 PM

Accepted Answer

This issue describes the same exception as your log contains:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.VisualStudio.ProjectSystem.ProjectException: The item type 'EntityDeploy' is not supported by this project item provider.

Unfortunatelly it does not have a direct solution.

Overall you shouldn't expect smooth functioning of EF tools with new csproj format. There is a discussion in EntityFramework6 repository which collects some of the known issues, both for migrations and EF tools. There is an explicit statement of EF team that we shouldn't expect near fixes for these problems:

On the flips side, working with EF6 in an ASP.NET Core application is possible but requires workarounds. E.g. in this case, keep the model in a separate .NET Framework library with a traditional project file, and unload any projects from the solution that use the new project system while working with migrations.

We are reluctant to commit to making EF6 migrations fully work with the new project system because we believe that would involve a significant investment which would hinder our progress on our main strategy, but perhaps there are less expensive things we can do to reduce the friction of the workarounds, e.g. make it so that you still need to put the EF6 model in a separate project but at least you don't need to unload other projects.

Regarding your problem I could suggest the following:

  1. Try updating to the latest Visual Studio version. I'm working with VS 2017 version 15.3.0 and I don't have the same issue as you get. I still get spontaneous error/warning messages during model generation and working with designer, however the model is generated correctly eventually.

  2. If it will not work for you, consider switching to the workaround suggested by EF team, i.e. keeping EF model in a separate library project with a traditional project file.

Well, such suggestions might not suit the perfectionists, but (again) new csproj format is not yet fully adopted by all existing VS tools and it's unknown for this moment when it happen.

6
3/22/2018 5:54:19 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow