【问题标题】:Why add-migration command is not creating migration? Not recognising packages为什么 add-migration 命令不创建迁移?无法识别包裹
【发布时间】:2017-04-03 13:28:00
【问题描述】:

安装以下软件包后:

"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final" (-Pre)

运行add-migration "InitialCreate" 命令时,出现以下错误:

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. 但是,如果您查看下面的.json 文件,您会看到包是匹配的,所以这个错误消息与我相矛盾。

这是我的project.json 文件:

{
  "runtimes": {
    "win10-x64": {}
  },

  "dependencies": {
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.NETCore.App": "1.1.0"
  },

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

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

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

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

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
} 

【问题讨论】:

    标签: c# asp.net entity-framework visual-studio entity-framework-core


    【解决方案1】:

    您需要更改您的project.json,如下所示。

    注意:需要包含"type": "platform"

    {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.1",
          "type": "platform"
        }
      }
    }
    

    您可以在此处阅读有关此问题的更多信息:GitHub

    【讨论】:

      【解决方案2】:

      如果您的解决方案中有多个项目。 使用 -projectname 选择合适的项目,像这样

      添加迁移 InitialCreate -ProjectName mydbProject

      将 mydbProject 替换为您的项目名称

      【讨论】:

        猜你喜欢
        • 2013-10-08
        • 1970-01-01
        • 2014-12-01
        • 2023-02-09
        • 1970-01-01
        • 2017-05-23
        • 2018-02-01
        • 2021-05-29
        • 1970-01-01
        相关资源
        最近更新 更多