I am posting this question just in case the solution I found would help someone else out. While working in Visual Studio 2017 rc4
each time I tried to run the Add-Migration
command in the Package Manager console I get the following error:
The term 'Add-migration' is not recognized...
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.
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.
- Close all VIsual Studio instances.
- Open VS.
- Open Package Manager console, let it be initialized.
- 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.
- On project select Manage Nuget Packages
- Browse and Search Microsoft.EntityFrameworkCore.Tools
- 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>
来源:https://stackoverflow.com/questions/42390942/the-term-add-migration-is-not-recognized-vs2017-and-entityframeworkcore