Search code examples
.netentity-frameworknugetentity-framework-migrations.net-7.0

Both 'Add-Migration' and 'Install-Package' are not recognised as an internal or external command. Microsoft.EntityFrameworkCore.Tools is installed


Trying to run an initial migration on an .NET 7 ASP.NET API project, but receiving the error

'add-migration' is not recognized as an internal or external command

I have seen several similar threads on StackOverflow that recommend installing "Microsoft.EntityFrameworkCore.Tools", however this is installed.

I have tried:

  • installing the package via .NET CLI, but receive the error 'install-package is not recognized as an internal or external command'
  • Clear the nuget data cache.
  • Clean-rebuild-restart Visual studio.

Unfortunately not sure where to go from here.


Solution

  • You need to invoke the commands in the Package Manager Console in Visual Studio.

    enter image description here

    Here is documentation about Package Manager Console.

    In your case:

    Installing the package for EF Core

    Install-Package Microsoft.EntityFrameworkCore.Tools
    

    Verify the installation

    Get-Help about_EntityFrameworkCore
    

    Adds a new migration.

    Add-Migration Init
    

    If you don't want to use the Package Manager Console and you prefer for example powershell you can use the dotnet ef tool.