'Microsoft.EntityFrameworkCore.Tools' is not installed in project on Scaffold-DbContext

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

Question

I'm following the tutorial listed here:

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

However, instead of including the DB context in the WebApplication project, I'd like the DB Context, Entities, etc to live inside another .NET Core Class Library.

I got around some early compatibility issues by updating the libraries project.json file to include the 'netcoreapp1.0' framework.

project.json

BEFORE:

{
    "version": "1.0.0-*",

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

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

AFTER:

{
  "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"
      }
    }
  }
}

The tutorial goes on to say that in order to 'reverse engineer your model' the following command must be run inside the package manager console:

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

I get the following error message:

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.

Where DB is the name of the class library.

You can clearly see Microsoft.EntityFrameworkCore.Tools in the tools section. So I'm not sure how to proceed.

1
0
7/26/2016 8:55:35 PM

Accepted Answer

There is no tools section within "framework" section defined in the project.json schema.

This one should work correctly

{
  "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"
      }
    }
  }
}
1
7/26/2016 8:49:52 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow