Add-Migration顯示錯誤EntityFrameworkCore.Design未安裝

c# entity-framework entity-framework-core nuget visual-studio

我在這裡按照EntityFrameworkCore的教程https://docs.efproject.net/en/staging/platforms/aspnetcore/new-db.html但是當我到達教程的創建數據庫部分https://docs.efproject .net / en / staging / platforms / aspnetcore / new-db.html#create-your-database並運行命令Add-Migration MyFirstMigration我收到以下錯誤:

Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed. Install the version of that package that matches the installed version of Microsoft.EntityFrameworkCore and try again.

我試圖安裝Microsoft.EntityFrameworkCore.Design以及Microsoft.EntityFrameworkCore.SqlServer.Design NuGet上的每個版本但仍然得到相同的錯誤。

我還嘗試使用該命令在NuGet PM之外運行

  • dotnet恢復
  • dotnet ef migrations添加MyFirstMigration

並得到以下錯誤:

Unhandled Exception: System.MissingMethodException: Entry point not found in assembly 'Microsoft.EntityFrameworkCore.Design, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

我嘗試了所有我能想到的東西,並在互聯網上到處尋找,但仍然沒有得到答案。

一般承認的答案

檢查您的project.json是否包含這些條目

在依賴下:

"Microsoft.EntityFrameworkCore.Design": {
  "version": "1.0.0-preview2-final",
  "type": "build"
},

"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",

在工具下:

"Microsoft.EntityFrameworkCore.Tools": {
  "version": "1.0.0-preview2-final",
  "imports": [
    "portable-net45+win8+dnxcore50",
    "portable-net45+win8"
  ]
},

熱門答案

首先,使用VS2015 Update2和VS2015最新版本的本文檔是Update 3.所以我建議你將VS2015升級到Update 3,它修復了很多VS錯誤。

然後根據教程,當我運行命令Add-Migration MyFirstMigration時,我收到相同的錯誤消息。然後我在Package Manager Console中運行命令“Install-Package Microsoft.EntityFrameworkCore.Design”來安裝EntityFrameworkCore.Design。安裝後,當我運行命令Add-Migration MyFirstMigration時,它添加成功。

以下是我的project.json文件內容。請檢查依賴項和工具版本。確保它們的版本正確。

"dependencies": {
"Microsoft.NETCore.App": {
  "version": "1.0.0",
  "type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview3-final",
"Microsoft.EntityFrameworkCore.Design": "1.0.1"
},

"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},


Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因