gpt4 book ai didi

entity-framework-6 - 为什么将模型 Entity Framework 添加到 csproj 失败?

转载 作者:行者123 更新时间:2023-12-04 07:58:02 25 4
gpt4 key购买 nike

这是我的项目文件 csproj

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

在 VisualStudio 2017 中,我尝试添加项目“ADO.NET 实体数据模型”。当按下添加按钮 VS 时抛出一个异常...

Exception

在日志文件中我得到了这个:

===================== 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()

最佳答案

This issue描述与您的日志包含相同的异常:

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.



不幸的是,它没有直接的解决方案。

总的来说,您不应该期望使用新的 csproj 格式的 EF 工具能够顺利运行。有一个 discussion在 EntityFramework6 存储库中,该存储库收集了一些已知问题,包括迁移和 EF 工具。 EF 团队明确声明,我们不应该期望这些问题近乎修复:

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.



关于你的问题,我可以提出以下建议:
  • 尝试更新到最新的 Visual Studio 版本。我正在使用 VS 2017 版本 15.3.0,但我没有遇到与您相同的问题。在模型生成和与设计人员合作期间,我仍然会收到自发的错误/警告消息,但是模型最终会正确生成。
  • 如果它对您不起作用,请考虑切换到 EF 团队建议的解决方法,即将 EF 模型与传统项目文件保存在单独的库项目中。

  • 好吧,这样的建议可能不适合完美主义者,但是(再次)新的 csproj 格式还没有被所有现有的 VS 工具完全采用,目前还不知道它何时发生。

    关于entity-framework-6 - 为什么将模型 Entity Framework 添加到 csproj 失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48915285/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com