未找到Add-Migration和Update-Database命令Visual Studio 2015

时间:2017-04-16 19:54:37

标签: sql-server entity-framework visual-studio-2015 asp.net-core-webapi

我已经看到了类似的问题,我已经尝试了所有发布的解决方案。在过去的两天里,我一直试图解决这个看似简单的问题而且无处可去。当我尝试从程序包管理器控制台运行Add-Migration或Update-Database时,出现以下错误:

  

更新 - 数据库:术语“更新 - 数据库”未被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。   在行:1个字符:1   +更新 - 数据库   + ~~~~~~~~~~~~~~~       + CategoryInfo:ObjectNotFound:(Update-Database:String)[],CommandNotFoundException       + FullyQualifiedErrorId:CommandNotFoundException

  

添加迁移:术语“添加迁移”不会被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。   在行:1个字符:1   +添加迁移TestMigration   + ~~~~~~~~~~~~~       + CategoryInfo:ObjectNotFound :( Add-Migration:String)[],CommandNotFoundException       + FullyQualifiedErrorId:CommandNotFoundException

这是我的project.json:

{
  "dependencies": {
    "Braintree": "3.5.0",
    "CoreCompat.System.Drawing": "1.0.0-beta006",
    "Google.Apis.Auth": "1.20.0",
    "Google.Apis.Oauth2.v2": "1.20.0.672",
    "MailKit": "1.10.1",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "RazorLight": "1.0.0-rc1",
    "RazorLight.MVC": "1.0.3",
    "SendGrid.NetCore": "1.0.0-rtm-00002",
    "Tinify": "1.5.0"
  },
  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.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
    }
  },
  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },
  "scripts": {
  "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

我尝试运行dotnet restore,重新启动Visual Studio,以管理员身份运行Visual Studio,重新启动计算机,删除EntityFramework的依赖项并重新添加它们。

我需要能够运行Add-Migration来更新我的SQL数据库,任何帮助都会受到赞赏。

修改

我最后只创建了一个新项目,再次安装所有依赖项并复制我的代码。这就行了,但实际的解决方案仍然可以提供帮助,并帮助处理类似问题的其他人。

1 个答案:

答案 0 :(得分:1)

只需从nuget安装Microsoft.EntityFrameworkCore.Tools软件包:

安装软件包Microsoft.EntityFrameworkCore.Tools-版本3.1.1

您还可以使用此链接来安装最新版本: Nuget package link

Nasir Jafarzadeh复制