efcore: dotnet ef not working in VS 2017

Steps to reproduce

  • Install VS 2017 RC
  • Create brand new web application with authentication
  • Add the require dependencies for migration builder
  • Open the package manager console and type dotnet ef

The issue

So I upgraded to Visual Studio 2017 and generated a new .net core web application with docker support. I am trying to create a new migration and getting an error about not finding an executable. When I installed 2017 I did check to install .NET core.

I went to look for the project.json file but there is none. I added a nuget package and I still cannot get it to generate a migration file for me.

“Microsoft.EntityFrameworkCore.Design”

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message:
Stack trace:
PM> dotnet ef
dotnet : No executable found matching command "dotnet-ef"
At line:1 char:1
+ dotnet ef
+ ~~~~~~~~~
    + CategoryInfo          : NotSpecified: (No executable f...and "dotnet-ef":String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 

Further technical details

Operating system: Windows 10 Visual Studio version: (e.g. VS 2013 or n/a) VS 2017

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 51 (14 by maintainers)

Most upvoted comments

@jrock2004 Look at this post https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-entity-framework-core-1-1/

Have you done this command PM> Install-Package Microsoft.EntityFrameworkCore.Tools.DotNet -Version 1.0.0-msbuild1-final -Pre

I’m trying to get this to work on VS2017 RC after upgrading my project. I’ve updated all packages and used Install-Package Microsoft.EntityFrameworkCore.Tools -Pre for tooling.

Now whenever I run Update-Database from the PowerShell Package Manager Console I get the following error:

PM> Update-Database dotnet exec needs a managed .dll or .exe extension. The application specified was ‘C:.…\bin\Debug\netcoreapp1.0<app>.runtimeconfig.json’ Process finished with non-zero exit code

Any idea what I have to do?

A couple of things to note. I’ve found that I’ve had better luck with 1.1 (all NuGet Packages, not just EF). 1.0 does not support named instances of SQL Server for example. You will have to check the box to include preview versions in NuGet when getting the tools, there is no RTM 1.1 version of the tools yet. Also, there is a bug that requires your project be on your OS drive. It only works through the NuGet Package Manager Console window right now. All that said, while it may not tell you much more, you can use the -Verbose and -Debug options on the command to get a little more information on the problem (see https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell), though I didn’t find it that helpful in my case. I think things will improve when there is a 1.1 release version of the tools and a release version of VS 2017. Right now, it’s a brittle process.

Some problem on Linux

uname -a Linux msmaldi-pc 4.8.0-1-amd64 #1 SMP Debian 4.8.5-1 (2016-10-28) x86_64 GNU/Linux

Microsoft.NETCore.App | 1.1.0 Microsoft.EntityFrameworkCore.Tools | 1.1.0-preview4-final

Microsoft .NET Core Shared Framework Host Version : 1.1.0 Build : 928f77c4bc3f49d892459992fb6e1d5542cb5e86

No executable found matching command "dotnet-ef"

For those having issues with dotnet ef, make sure when in powershell / dotnet cli (in VS), to navigate to the proper directory containing your .csproj file.

In Visual Studio it probably defaults to the top level (above /src), you’ll to navigate down /src/project, then run your dotnet ef commands.

@ccampbellclearesult to make a dB connection place this in Startup.cs file:

public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();
            services.AddMvc().AddJsonOptions(options => {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });
            var connection = @"Server=(localdb)\mssqllocaldb;Database=APPLICATION_NAME.AspNetCore.NewDb;Trusted_Connection=True;";
            services.AddDbContext<APPLICATION_NAME.Context>(options => options.UseSqlServer(connection));
        }

@MikeYeager See #7358 for what packages to install.

You CAN use “dotnet ef” in the Package Manager Console.

You just have to “cd” to the root directory of your project; where the .csproj file lives. (Or whichever one you’re using.)

This is especially handy when using a .csproj, because commands like “Add-Migration” do not work for .csproj files (yet).

@freerider7777 dotnet ef isn’t for use in Package Manager Console, it’s for use outside of VS at the command line. You would use the Package Manager Console commands in Microsoft.EntityFrameworkCore.Tools (Add-Migration, Update-Database, etc.).

@jrock2004 It seems that you haven’t installed the latest SDK for .NET Core. You can find it here https://go.microsoft.com/fwlink/?LinkID=835014

Then, retry 2michel34’s link