1
votes

I am using Visual Studio 2015 and trying to install the dependencies for scaffolding my databases classes. This is the Project.json:

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "NETStandard.Library": "1.6.0"
  },

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

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "net451"
    }
  }
}

However, the Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final is not installed, stating this error:

enter image description here

How to resolve this issue?

1

1 Answers

0
votes

Since EF is not compatible yet with .NET Standard, we have to make the class library works with .NET Core. Add the necessary dependency and then modify the library to be a startup.

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

Open Package Manager Console, then install the following packages:

  • Run Install-Package Microsoft.EntityFrameworkCore.SqlServer
  • Run Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
  • Run Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design

Add the necessary tool to project.json

tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
}

The project.json should be similar to this:

{
  "buildOptions": {
    "emitEntryPoint": true
  },
  "frameworks": {
    "netcoreapp1.0": {}
  },
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1"
  },
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final"
    }
  }
}

Now, Create a folder named "Models", your generated classes will reside there.

Now, run the following command to scaffold the database:

  Scaffold-DbContext "Server=YourServer;Database=YourDB;User Id=sa;Password=yourPassword;"
 Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models