繁体   English   中英

未找到添加迁移和更新数据库命令 Visual Studio 2015

[英]Add-Migration and Update-Database commands not found Visual Studio 2015

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

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

或者

添加迁移:术语“添加迁移”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。 在 line:1 char:1 + Add-Migration 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 数据库,任何帮助将不胜感激。

编辑:

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

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

安装包 Microsoft.EntityFrameworkCore.Tools -Version 3.1.1

您也可以使用此链接安装最新版本: Nuget 包链接

复制自Nasir Jafarzadeh

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM