The term 'Add-migration' is not recognized - VS2017 and EntityFrameworkCore

a 夏天 提交于 2019-11-30 08:03:13

You just need to initialize the powershell module. I believe this is a bug, but it's pretty easy to work around. All you need to do is find the init.ps1 file and dot source it.

Just type this into the package manager console:

C:\Users\YourUserAccount\.nuget\packages\Microsoft.EntityFrameworkCore.Tools\1.1.0-preview4-final\tools\init.ps1

Now the version might be different for you, depending on which one you have installed. Make sure you dot source the same version that is in your project.

Ask

The solution that worked for me after trying a whole raft of other solutions posted, was to:

  • right click on my project
  • select Manage Nuget Packages
  • select the browse tab
  • thick Include prerelease check box
  • install the Microsoft.EntityFrameworkCore.Tools

N.b that aspnetcore project in visual studio 2017 do not seem to have the project.json file.

Hi There

This is almost an normal problem in Microsoft, and they pointing out the same solution:

Microsoft Docs - Getting Started with EF Core on ASP.NET Core with a New database

For me above dosn't solve my problem, but this line first does:

PM> Install-Package Microsoft.EntityFrameworkCore.Tools
PM> add-migration InitialCreate

/Cheers, Jan

Download the latest .net Core 2.0 from the link below and it will fix your issue: https://www.microsoft.com/net/core#windowscmd

I reinstalled package Microsoft.EntityFrameworkCore.Tools and issue got fixed for me.

It works for me.

  1. Close all VIsual Studio instances.
  2. Open VS.
  3. Open Package Manager console, let it be initialized.
  4. Now open the project and try Add-Migration.

For me, I had to copy the folder microsoft.entityframeworkcore.tools from

C:\Program Files\dotnet\sdk\NuGetFallbackFolder

To

C:\Users\<user>\.nuget\packages

I have had the same problem with a project created with VS2017 version 15.9.4 and .Net Core 2.1.

I have fixed it by adding Microsoft.EntityFrameworkCore.Tools to dependences of my project.

  1. On project select Manage Nuget Packages
  2. Browse and Search Microsoft.EntityFrameworkCore.Tools
  3. Install it on your project

Then you can open Package Manager Console and use commands : Add-Migration Drop-Database Get-DbContext Scaffold-DbContext Script-Migrations Update-Database

Regards dcube

You have to add this to your CSPROJ file. This will most likely be fixed when the Core 2.0 is released. This stems from an issue where you can not install this package Microsoft.EntityFrameworkCore.Tools.DotNet using the NUGET tools due to version requirements.

Then using CMD/PowerTools in the project directory you can issue the following commands:

dotnet ef migrations add InitialCreate

dotnet ef database update

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
</ItemGroup>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!