EF7 commands do not work in VS2015 CTP 6

2019-08-06 15:45发布


I'm trying to run ef7 migration on fresh asp.net 5 preview project.
Steps I took:

  1. Created fresh project based on template "ASP.NET 5 preview starter web"
  2. Build it
  3. Try command Add-Migration in Package Manager console

Result:

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

I also try this command:

Install-Package EntityFramework.Commands -Pre

I think for VS 2015 project is redundant, it executed but still Add-Migration was not recognized.

Thanks in advance for clues...

2条回答
ゆ 、 Hurt°
2楼-- · 2019-08-06 16:31

Ok, I know this is an old question and it has already been technically answered. That is, if you want to open command prompt and do it. The root cause of this problem is that the PowerShell module is not initializing. There is a simple fix though. You just need to initialize the module. Go to your solution explorer. Go to References >> .NETCoreApp,Version=v1.0 then scroll down until you find Microsoft.EntityFrameworkCore.Tools right click and show the properties. Take note of the path it should be something like

C:\Users\YourUserName\.nuget\packages\Microsoft.EntityFrameworkCore.Tools\1.0.0-preview2-final

Once you have that go to the path location in file explorer. You should see another folder called tools. Inside that folder you will see a .ps1 file called init.ps1. This is the module that we need to initialize. So go back to Visual Studio, I am using VS 2015 pro and Win 10 pro, open the package manager console. Type in the following

cd "C:\Users\YourUserName\.nuget\packages\Microsoft.EntityFrameworkCore.Tools\1.0.0-preview2-final\tools"

and press enter. Then to initialize a module in PowerShell you just need to type

. .\init.ps1

or I believe you can just do the entire path and get the same results so that way would be

C:\Users\YourUserName\.nuget\packages\Microsoft.EntityFrameworkCore.Tools\1.0.0-preview2-final\tools\init.ps1

Unfortunately you would have to do this every time that error pops up, but its not that bad if you just save the path in a .txt file or comment it somewhere in your project that is easy to find.

查看更多
疯言疯语
3楼-- · 2019-08-06 16:35

NuGet commands don't work with ASP.NET 5 projects. You'll need to use the ASP.NET 5 command-line versions of the commands. (E.g. k ef migration add) We have an issue aspnet/DNX#952 open to unblock this scenario, but it hasn't seen much activity.

To learn more about the ASP.NET Commands, see my post EF7 Migrations: ASP.NET Commands.

查看更多
登录 后发表回答