Scaffold-DbContext: The term ‘Scaffold-DbContext’ is not recognized as the name of a cmdlet

Today in this article, we will cover below aspects,

Issue Description -The term ‘Scaffold-DbContext’ is not recognized

dotnet CLI or Nuget package manager console(PMC) gives the below error “scaffold-dbcontext is not recognized” for scaffolding command.

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.

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

Resolution

The issue was found to be due to the missing of necessary tools required for the scaffolding of Database entities.

Using Visual Studio to resolve

This issue can be fixed by installing the below Nuget package using the Package manager console within the project,

PM> Install-Package Microsoft.EntityFrameworkCore.Tools

If you would like to verify installed EF Core tools please run the below command,

PM> Get-Help about_EntityFrameworkCore

'Scaffold-DbContext' is not recognized

Finally please run your scaffolding commands as below,

Example

Scaffold-DbContext "Your Connection String" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables "Your-Table-Name" -ContextDir Context -Context "your context name'

After successful command, you shall be able to scaffold a single table or scaffold multiple tables of your Database.

the term'scaffold-dbcontext' is not recognized as the name of a cmdlet

Generated files will be created within your project directory.

Overall you shall be needing below NuGet package for EFCore implementation ,

– Microsoft.EntityFrameworkCore

-Microsoft.EntityFrameworkCore.Design

-Microsoft.EntityFrameworkCore.SqlServer

-Microsoft.EntityFrameworkCore.Tools

Alternatively, you should be able to use efcore global tool for scaffolding as discussed below.

Using CLI command

If not using Visual Studio, please install the Global tool as below,

The Entity Framework Core CLI tool that is dotnet-ef can be installed as below. The CLI tools are cross-platform and easy to use.

dotnet tool install --global dotnet-ef

Example:

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.

Followed by adding the below package using CLI (Please use the project location directory to run this command)

Example:

 dotnet add package Microsoft.EntityFrameworkCore.Design 

Once installed successfully, please verify the installation by running the below command,

dotnet ef 

blank

You are all set! Please run the different Scaffold-DbContext commands to generate the required scaffolding as explained above.

References:

Happy Coding !!

Did the above steps resolve your issue?

Please sound off in your comments below!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



2 thoughts on “Scaffold-DbContext: The term ‘Scaffold-DbContext’ is not recognized as the name of a cmdlet

Leave a Reply

Your email address will not be published. Required fields are marked *