vs2010 安装EF 的几种方法

背景①:利用NuGet来安装EFCodeFirst方法

①我们可以利用NuGet包管理器(安装ASP.NET MVC3时会自动安装)来把EFCodeFirst类库添加到我们的Mvc工程中。这个类库使得我们可以直接使用code-first。点击“工具”菜单下的“Library Package Manager”子菜单下的“Add Library Package Reference”菜单选项;


②点击“Add Library Package Reference”菜单选项后,将会弹出一个对话框,标题为“Add Library Package Reference”;


③默认状态下,左边的“All”选项处于选择状态。因为还没有安装任何包,所以右边面板中显示“找不到任何项”。点击左边面板中的“online”选项,NuGet包管理器将会在服务器上检索所有当前能够获取的包;


④服务器上有几百个当前能够获取的包,现在我们只关注EFCodeFirst包。在右上角的搜索输入框中输入“EFCode”。在检索结果中,选择EFCodeFirst包,并且点击Install按钮安装包;


⑤点击了install按钮后,会弹出一个接受许可证窗口,在这个窗口中必须要点击“I Accept”按钮,接受许可证条款,安装才能继续进行。

⑥安装完毕后,点击close按钮。我们的Mvc工程中会自动加载EntityFramework程序集,其中包含了EFCodeFirst类库。

背景②:让事实说话

今天在Win 7下利用NuGet来安装EFCodeFirst package时,出现错误:This package(or one of its dependencies) contains PowerShell scripts and needs to be installed from the Package Manager Console。

师兄的XP下出现该提示的解决方法是打一个微软的补丁KB968930,下载地址:

http://www.microsoft.com/downloads/zh-cn/results.aspx?freetext=KB968930&displaylang=zh&stype=s_basic

里面有XP,Vista,Windows Server 2003及2008的32位,64位版本,但是没有Win 7版本的,

微软对该补丁的描述如下:

Windows XP 更新程序 (KB968930)
Windows Management Framework Core 程序包提供了适用于 IT 专业人员的已更新管理功能。

用于 Windows Server 2008 的 Windows PowerShell 2.0 和 WinRM 2.0 (KB968930)
Windows Management Framework Core 程序包包括 Windows PowerShell 2.0 和 Windows Remote Management (WinRM) 2.0。

解决鸟:后来根据提示找到了一个在控制台进行安装的解决方法:

①博客园原文内容如下:

I tried to install EntityFramework 4.1 on VS 2010 through NuGet. I searched and found the package through “Tools > Library Package Manager > Add Library Package Reference” tool and I got this error: “This package (or one of its dependencies) contains powershell scripts and needs to be installed from the package manager console.”. This is what I did to fix it:

Tools > Library Package Manager > Package Manager Console
PM > get-package -remote -filter entityframework
(got some results including EntityFramework 4.1.10311.0)
PM > install-package -id EntityFramework
Successfully added ‘EntityFramework …

②根据提示,在控制台安装会出现如下信息(以下蓝色内容为需要输入的命令):

Each package is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Some packages may include dependencies which are governed by additional licenses. Follow the package source (feed) URL to determine any dependencies.

PM> get-package -remote -filter entityframework

Id Version Description
– ——- ———–
Check_My_Box_Packages 1.1.0.2 This Package uses MvcScaffolding, EntityFramew…
Check_My_Box_Packages 1.1.0.3 This Package uses MvcScaffolding, EntityFramew…
EFCodeFirst 1.0 Legacy package, Code First is now included in …
EFCodeFirst 1.1 Legacy package, Code First is now included in …
EntityFramework 4.1.10311.0 DbContext API and Code First workflow for ADO….
EntityFramework 4.1.10331.0 DbContext API and Code First workflow for ADO….
EntityFramework.Patterns 0.2 Provides different patterns to be used with En…
EntityFramework.Sample 4.1 This sample blog model demonstrates the use of…
EntityFramework.SqlServerCompact 4.1.8482.1 Allows SQL Server Compact 4.0 to be used with …
EntityFrameworkProfiler 1.0.0.839 EntityFramework Profiler is a real-time visual…

PM> install-package -id EntityFramework
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkID=211010. 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.
已成功安装“EntityFramework 4.1.10331.0”
已成功将“EntityFramework 4.1.10331.0”添加到 MvcMovie

PM>


你可能感兴趣的:(library,reference,dependencies,entityframework,powershell,2010)