關於VS2010中無法進級EntityFramework的解決辦法


VS2010 MVC3利用NuGet來安裝EFCodeFirst package失敗解決方法

背景①:利用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

 

題目如下:

  1. 解決規划:

1)封閉VS2010

2)從頭下載NuGet

3)打開VS2010
//若是顯示如圖

//則默示你 沒有選擇景象

How to use it

      1. Open a project in Visual Studio (it doesn""t matter which - if you try to install a package outside of a solution, you""ll get slapped down with "The current environment doesn""t have a solution open").
      2. Open the Package Manager console (View / Other Windows / Package Manager Console).
      3. Type "install-package NuGet.Downloader" - you should see "Successfully installed ""Nuget.Downloader 1.0.0.5""." (with whatever the current version number is).
      4. This adds a new commend to the Package Manager console, Download-Packages. You can run it without any parameters, which will grab the top 500 most popular NuGet packages and drop them in a new LocalNuGet folder inside your My Documents folder.
      5. If desired, uninstall the package using Uninstall-Package.

//你須要做的就是設置DefaultProject

4)再用PM> install-package -id EntityFramework -Version 4.2.0.0號令進級即可

 

Nuget 這個工具最先是在MIX11上開始讓我注意.不知道當時看MIX同學是否注意到一個小細節.-就是所有MIX11 Code演示環節中MS開發人員都使用Nuget.本篇介紹一些Nuget安裝和一些在實際項目中基本用法.

首先 解釋一下Nuget Tool是什么?

2011-12-20_183915

NuGet 是一種 Visual Studio 擴展工具,它能夠簡化在 Visual Studio 項目中添加、更新和刪除庫(部署為程序包)的操作。 NuGet 程序包是打包成一個文件的文件集,擴展名是 . nupkg,使用開放打包約定 (OPC) 格式.

在沒有使用Nuget工具之前.如果我們要在一個普通.NET項目中添加一個庫的引用.最簡單的方式就是添加DLL引用的方式實現第三方代碼庫引用.通過下載解壓.添加引用操作.如果在發布時還需要為項目依賴項進行大量手工整理.是否發現.在DLL引入到發布整個過程存在一個管理”真空“狀態.如果要向其他開發者或組織共享我們代碼.是否意味更復雜的操作.着恰恰也是Nuget所做的.

安裝Nuget有兩種方式.方式一打開Visual Studio 2010,打開Tool->Extension Manager窗體.選擇Online Gallery,在搜索框中輸入NuGet看到:

extension-manager-with-nuget

點擊Download下載會自動安裝,另外一種方式打開http://www.nuget.org/直接下載安裝文件NuGet Manager . 點擊運行開始安裝:

2012-01-04_105511

選擇安裝工具 下一步:

2012-01-04_105518

安裝完成.如果在安裝過程出現錯誤貨沒有正確安裝會在安裝界面提示:

2012-01-04_115357

關於安裝出錯后通過查看Install Log 確定出錯的原因:

2012-01-04_115744

如果覺得麻煩.也可以不看.直接找到上圖的目錄刪除掉NuGet Package Manager文件夾,重新安裝Nuget Tool即可.安裝完成后可以創建一個Windows phone Application 打開Tool->Library Package Manager->Package Manager Console:

2012-01-04_135817

可以通過在控制台Package Manager Console 輸出目錄管理庫 首先在在線的http://www.nuget.org/packages目錄下找到對應庫初始化路徑 類似找到Json.NET http://www.nuget.org/packages/Newtonsoft.Json 初始化路徑為:

2012-01-04_140447

輸入:Install-Package Newtonsoft.Json

2012-01-04_140616

如果對應庫文件較大.則會在Visual Studio 右下角提示有下載進度.安裝完成后:

2012-01-04_140921

可以在當前項目目錄中看到已經成功添加到引用中:

2012-01-04_141025

 

 

 

 

 

 

 

 

 

可以引用管理手動添加庫文件.在解決方案的References引用可以看到:

2012-01-04_141245

多了一個Manage Nuget Packages打開管理窗體能夠實現已經安裝庫文件管理:

2012-01-04_141459

Nuget提供基於 Windows PowerShell 的控制台窗口(稱作程序包管理器控制台)以及一組 Windows PowerShell 命令與 NuGet 進行交互。 Windows PowerShell 是基於 .NET 的腳本語言和命令行 shell,非常適合組成命令集,並能夠處理對象.當然PowerShell提供強大支持可以Package Manager Console通過指令直接管理卸載庫 例如卸載已經引用Json.NET庫輸入:Unstall-Package Newtonsoft.Json卸載.如果想看到當前項目已經引用的Package在Console 直接通過指令的方式獲取 Get-Package:

2012-01-04_142207

 

 

 

看到當前項目中已經使用庫文件 以及版本其他信息.如果已經引用的組件存在新的版本 依然可以通過Update-Package批量更新已經引用的庫:

2012-01-04_143018

 

命令嘗試將每個程序包都更新到最新版本,如果任何程序包包含重大改變,這會是一項非常重大的操作。 在多數情況下,您僅希望將各程序包更新至最新的修補程序版本。 這叫“安全”更新,前提是具有較大內部版本號或修訂號(但具有相同的主版本號和次版本號)的程序包能夠向后兼容。 僅添加 Safe 標記以執行安全更新:例:Update-Package –Safe

當然我們能夠現在操作都是基於在線Nuget官方數據源Package操作.當然我們可以PAckage數據源設置成本地 找到綠色按鈕Package Manager Settings:

2012-01-04_143814

打開並在一個指定本地目錄下添加一個本地Package數據源:

2012-01-04_143950

能在Console看到指定的數據源設置分類LocalPackages:

2012-01-04_144057

當然對於組織結構更大的公司和開發團隊.如果簡單的使用SVN和Git管理方式依然不容易控制不同庫版本和對外共享的控制.Nuget針對企業用戶提供可以在企業內部搭建一個Nuget Server的形式來統一管理內部開發團隊庫共享. 大大提高開發效率.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM