' Microsoft.EntityFrameworkCore.Tools'未安装在Scaffold-DbContext上的项目中

时间:2016-07-26 20:43:09

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

我按照此处列出的教程进行操作:

https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html

但是,我不想在WebApplication项目中包含DB上下文,而是希望DB Context,Entities等能够存在于另一个.NET Core类库中。

我通过更新库project.json文件来解决一些早期兼容性问题,以包含' netcoreapp1.0'框架。

project.json

在:

{
    "version": "1.0.0-*",

    "dependencies": {
        "NETStandard.Library": "1.6.0"
    },

    "frameworks": {
        "netstandard1.6": {
            "imports": "dnxcore50"
        }
    }
}

在:

{
  "version": "1.0.0-*",

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [ "portable-net451+win8" ],
      "buildOptions": {
        "emitEntryPoint": true
      },

      "dependencies": {
        "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
        "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0-*"
        },
        "Microsoft.EntityFrameworkCore": "1.0.0-*",
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-*"
      },
      "tools": {
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-*"
      }
    },
    "netstandard1.6": {
      "imports": "dnxcore50",
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    }
  }
}

本教程接着说,为了对您的模型进行反向工程,'必须在包管理器控制台中运行以下命令:

Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

我收到以下错误消息:

Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project 'src\DB'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.

其中DB是类库的名称。

您可以在工具部分清楚地看到Microsoft.EntityFrameworkCore.Tools。所以我不确定如何继续。

1 个答案:

答案 0 :(得分:1)

"框架内没有工具部分" project.json schema中定义的部分。

这个应该可以正常工作

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-*"
  },
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-*"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [ "portable-net451+win8" ],
      "buildOptions": {
        "emitEntryPoint": true
      },
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0-*"
        }
      }
    },
    "netstandard1.6": {
      "imports": "dnxcore50",
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    }
  }
}