none
The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program. RRS feed

  • Question

  • I am creating a .Net Core 1.0.1 Web API in Visual Studio 2015 Update 3, using EF Core.
    I am trying to reverse engineer to a model from a database hosted locally on Sql Server 2016 Express, on my Windows 10 Home 64 bit PC.

    I am following this tutorial: Tutorial

    The tutorial say I need to run this command in the Package Manager Console to reverse engineer my model:

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

    So, I modified the connection string to connect to my database as follows:

    Scaffold-DbContext "Data Source=DESKTOP-AEAOCON\SQLEXPRESS;Initial Catalog=propworx;Integrated Security=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

    and ran it. But I get the following 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 "Data Source=DESKTOP-AEAOCON\SQLEXPRESS;Initial Ca ...
    + ~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Scaffold-DbContext:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

    The tutorial does mention the following:

    If you receive an error stating the term ‘Scaffold-DbContext’ is not recognized as the name of a cmdlet, then close and reopen Visual Studio.

    But I've done this and it hasn't helped. Any ideas anyone?

    This is my project.json file:

    {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.1",
          "type": "platform"
        },
        "Microsoft.AspNetCore.Mvc": "1.0.1",
        "Microsoft.AspNetCore.Routing": "1.0.1",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
        "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",
        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
        "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1"
      },
    
      "tools": {
        "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
        }
      },
    
      "publishOptions": {
        "include": [
          "wwwroot",
          "**/*.cshtml",
          "appsettings.json",
          "web.config"
        ]
      },
    
      "scripts": {
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
      }
    }
    Thanks...

    Fabricio Rodriguez - Pretoria, South Africa


    • Edited by Fabs1977 Thursday, November 3, 2016 1:32 PM
    • Moved by CoolDadTx Thursday, November 3, 2016 2:05 PM EF related
    Thursday, November 3, 2016 1:31 PM

Answers

  • Hi Fabs,

    Thank you for your post.

    >>"Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed."

    Based on your description, Microsoft.EntityFrameworkCore.Design is missing in your project. Please add following configuration section under dependencies.

    "Microsoft.EntityFrameworkCore.Design": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },

    Best Regards,
    Li Wang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Fabs1977 Monday, October 30, 2017 7:18 AM
    Monday, November 7, 2016 1:44 AM

All replies

  • Ok, I added these two lines to the project.json file:

    "Microsoft.EntityFrameworkCore.Tools""1.0.0-preview3-final", "Microsoft.EntityFrameworkCore.SqlServer.Design""1.0.1"

    which is apparently required for the Scaffold-DbContext to work... But now I get this error:

    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.

    This is what my project.json file looks like now:

    {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.1",
          "type": "platform"
        },
        "Microsoft.AspNetCore.Mvc": "1.0.1",
        "Microsoft.AspNetCore.Routing": "1.0.1",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
        "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",
        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
        "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview3-final",
        "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1"
      },
    
      "tools": {
        "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
        }
      },
    
      "publishOptions": {
        "include": [
          "wwwroot",
          "**/*.cshtml",
          "appsettings.json",
          "web.config"
        ]
      },
    
      "scripts": {
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
      }
    }


    Fabricio Rodriguez - Pretoria, South Africa


    • Edited by Fabs1977 Friday, November 4, 2016 10:41 AM
    Friday, November 4, 2016 10:36 AM
  • Hi Fabs,

    Thank you for your post.

    >>"Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed."

    Based on your description, Microsoft.EntityFrameworkCore.Design is missing in your project. Please add following configuration section under dependencies.

    "Microsoft.EntityFrameworkCore.Design": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },

    Best Regards,
    Li Wang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Fabs1977 Monday, October 30, 2017 7:18 AM
    Monday, November 7, 2016 1:44 AM
  • Hi Li, thanks for the reply. I do actually have that line in the project.json file:

    "Microsoft.EntityFrameworkCore.SqlServer.Design""1.0.1"

    It's a different version to what you posted, but that shouldn't matter right? Anyway, I did replace my line with yours, but it didn't make a difference... Still getting the same error...


    Fabricio Rodriguez - Pretoria, South Africa


    • Edited by Fabs1977 Monday, November 7, 2016 12:21 PM
    Monday, November 7, 2016 10:36 AM
  • Sorry, I Just realized your line was slightly different to mine. But yeah, as I said, I did add your suggestion to project.json but it didn't help... I tried adding it to both the "dependencies" section and the "tools" section...

    Fabricio Rodriguez - Pretoria, South Africa

    Monday, November 7, 2016 12:25 PM
  • Ok, I read somewhere .Net cannot create model in a Class Library project, so I tried again in a Console application. I now get a different error message :(

    PM> Scaffold-DbContext "Data Source=DESKTOP-AEAOCON\SQLEXPRESS;Initial Catalog=propworx;Integrated Security=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Verbose
    Using framework 'netcoreapp1.0'
    Using data directory 'c:\users\fabs-lenovoy70\documents\visual studio 2015\Projects\ConsoleApp1\src\ConsoleApp1\.\bin\Debug\netcoreapp1.0'
    Build started...
    Build failed.


    Fabricio Rodriguez - Pretoria, South Africa

    Monday, November 7, 2016 12:57 PM
  • Ok, I read somewhere .Net cannot create model in a Class Library project, so I tried again in a Console application. I now get a different error message :(

    PM> Scaffold-DbContext "Data Source=DESKTOP-AEAOCON\SQLEXPRESS;Initial Catalog=propworx;Integrated Security=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Verbose
    Using framework 'netcoreapp1.0'
    Using data directory 'c:\users\fabs-lenovoy70\documents\visual studio 2015\Projects\ConsoleApp1\src\ConsoleApp1\.\bin\Debug\netcoreapp1.0'
    Build started...
    Build failed.


    Fabricio Rodriguez - Pretoria, South Africa

    Monday, November 7, 2016 1:14 PM
  • Hi Fabs1977,

    Could you please provide a bit more information, such detailed error message.

    In addition, since it is a asp.net core issue, you could also post your issue on the following forum for support.

    https://forums.asp.net/1255.aspx/1?ASP+NET+Core

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 15, 2016 9:53 AM
    Moderator