NuGet Console in visual studio 2017 RC won't Add-Migration or Update-Database?

3k views Asked by At

I recently got a new computer and saw there was a new version of Visual Studio. I tried to Update-Database in Nuget Manager Console but I get this.

The Entity Framework Core commands for the Package Manager Console don't yet support csproj-based .NET Core projects. Use the .NET Command Line Tools (i.e. dotnet ef) instead. For more details, see https://go.microsoft.com/fwlink/?linkid=834381.

I then follow the instructions to use dotnet CLI (never used it before so not sure how to use it) added the tools then restored dotnet as it says. I then enter dotnet ef database update to add the migrations I already have but this comes up:

dotnet : No executable found matching command "dotnet-ef"

At line:1 char:1

  • dotnet ef database update
  • CategoryInfo : NotSpecified: (No executable f...and "dotnet-ef" :String) [], RemoteException
  • FullyQualifiedErrorId : NativeCommandError
3

There are 3 answers

1
Dave Mertens On

I assume that you have added the the ef-tools package to your project.json tools section?

You should have a section that looks like this:

"tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final"
},

I usually open the nuget package console and type the migration commands there. No need to prefix that command with 'dotnet ef' anymore. That way it is not very different from the EF6 framework experience.

I just found also a good tutorial on the asp.net core website: https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db

0
Weiwei On

Please locate to the path of your project where the project.json file stored. You could use "cd" command in Package Manager Console to locate the path first. Then type "dontnet ef" again.

Because Package Manager Console can only understand "dotnet-ef" when it is in the project folder(folder with project.json in it).

0
John Pezzanite On

I've had the same issues with Entity Framework Core. You need to be 100% sure there are no problems with your code and NuGet dependencies. When I run into these issues now I run Code Analytics and resolve all issues there. If that doesn't work I go to the command line at the project and run:

dotnet restore
dotnet build
dotnet pack 

Again I resolve any issue that might come up.

This works a little over 80% of the time. If that doesn't expose what is tripping up EF, I then run Publish of my web app.

For me, some of the errors are coming from my Seed Data routines -- even though they are not called. I have resorted to commenting out the entire Seed Data code to get EF to work.

Thanks, John