EF Core Database First Approach: Scaffold-DbContext is not recognized as the name of a cmdlet

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

Question

I am using EF Core and I am trying to generate the Model from the Database. I have created a separate ASP.NET Core Web Application, because generating that from a class library didn't work for me.

I have generated the entity classes from the database successfully several times, but suddenly it stopped working. This is really weird because I this is not the first time, and I am not change anything, what's causing it to stop working?

This is project.json:

  {
  "dependencies": {
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    },
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0"
  },

  "tools": {

    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.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
    }
  }
}

This is the command:

 Scaffold-DbContext "Server= myserver;Database=db;User Id=sa;Password=pass;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir EntityModels 

The Error:

 Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Scaffold-DbContext "Server=myserver;Database=db...
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Scaffold-DbContext:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I restarted visual studio and the problem persists.

1
1
2/4/2017 1:22:56 PM

Popular Answer

The version in dependencies is different than tools:

From dependencies:

"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",

And from tools:

"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",

1
2/4/2017 12:13:01 AM


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