实体框架5在VS 2012中安装失败

时间:2012-12-11 17:37:53

标签: entity-framework visual-studio-2012 nuget

我正在尝试从Visual Studio 2012中的程序管理器控制台安装最新版本的EntityFramework。运行install-package命令会产生以下错误:

PM> install-package EntityFramework
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=253898&clcid=0x409. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
    Successfully installed 'EntityFramework 5.0.0'.
    Successfully uninstalled 'EntityFramework 5.0.0'.
    Install failed. Rolling back...
    install-package : Failed to add reference to 'System.Data.Entity'. Please make sure that it is in the Global Assembly Cache.
    At line:1 char:1
    + install-package EntityFramework
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
        + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

所以我在Google上做了一些讨论,并提出以下内容进入Web.Config文件。我第二次尝试使用以下条目安装EntityFramwork:

<section name="entityFramework" type="EntityFramework.dll, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

导致同样的错误。我的问题是这些:

  • 如何安装此软件包?开箱即用,这应该可行,并与其他软件包一起工作,这看起来很愚蠢,因此无法快速轻松地安装此软件包。

  • 此软件包的文档以及某种形式的常见问题解答存在于何处?对于安装问题的文档不存在,这似乎很愚蠢。

提前致谢!

::编辑::

我忘了添加我也尝试了以下条目到web.config文件:

<assemblies>
    <add assembly="System.Data.Entity, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </assemblies>

......产生了同样的错误。

4 个答案:

答案 0 :(得分:13)

对于我们来说,这个错误是由于针对错误的.NET版本造成的 - 我们意外地创建了针对.NET的项目2.将目标框架版本更改为.NET 4解决了问题并允许我们添加实体框架的NuGet包。

答案 1 :(得分:3)

我有类似的错误。从4.5回到.NET 4.0后,EF安装好了。 (Visual Studio Express 2012 for Web)

答案 2 :(得分:2)

删除您对web.config文件所做的所有输入。只需Right Click on your project name in the solution,点击Manage Nuget Packages在左侧点击Online,然后在右侧将实体框架放入搜索框。点击Install

这将自动为您完成所有事情。

答案 3 :(得分:1)

我发现我只需要再次尝试在NuGet中添加它;它第二次工作。也许安装脚本中存在错误。