EF核心數據庫第一種方法:Scaffold-DbContext不被識別為cmdlet的名稱

asp.net-core c# entity-framework-core

我正在使用EF Core,我正在嘗試從數據庫生成模型。我創建了一個單獨的ASP.NET核心Web應用程序,因為從類庫生成它對我不起作用。

我已經成功地從數據庫生成了幾次實體類,但突然間它停止了工作。這真的很奇怪,因為我這不是第一次,我沒有改變什麼,是什麼導致它停止工作?

這是project.json:

  {
  "dependencies": {
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    },
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0"
  },

  "tools": {

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

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  }
}

這是命令:

 Scaffold-DbContext "Server= myserver;Database=db;User Id=sa;Password=pass;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir EntityModels 

錯誤:

 Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Scaffold-DbContext "Server=myserver;Database=db...
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Scaffold-DbContext:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我重新啟動了visual studio,問題仍然存在。

熱門答案

dependencies的版本與tools不同:

來自dependencies

"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",

tools

"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow