Home » C# » Scaffold-DbContext – Scaffold DBContext not recognized

Scaffold-DbContext – Scaffold DBContext not recognized

By Emily

If you are using Entity Framework and a database first method then you will need to use the Scaffold-DbContext command. This will build all the model and context files needed to get and set data in your database. When running the Scaffold-DbContext command, if you get an error message like “scaffold-dbcontext is not recognized” then this post will explain how to resolve it.

Why am I seeing the message “scaffold-dbcontext is not recognized”?

If you see this message after using the Scaffold-DbContext command :

'Scaffold-DbContext' is not recognized as an internal or external command, operable program or batch file.

… then you’re probably trying to run the command in the wrong place! If you try using it in Powershell or CMD you’ll see something like this:

How to resolve Scaffold-DbContext' is not recognized as an internal or external command

To resolve the issue you need to run the Scaffold-DbContext command in the Package Manager Console.

Getting a Build failed message

If you get a build failed message after running the Scaffold-DbContext command then check the your entire solution builds successfully first. If there are any build errors it won’t run – take note that the entire solution must build, not just the project.

Some people report that they have to use the dotnet build command to actually see the errors that are causing the problem – it’s worth checking out this thread if you are having the same experience – https://stackoverflow.com/questions/38961115/build-failed-on-database-first-scaffold-dbcontext

I’d also suggest you make sure you have EF Core installed in the project you are scaffolding into…… in fact make ysure you have all 3 of these packages installed.

  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.EntityFrameworkCore.Tools
  • Microsoft.EntityFrameworkCore.Design