Efcore: dotnet ef not working in VS 2017

Created on 17 Nov 2016  路  51Comments  路  Source: dotnet/efcore

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

closed-question

Most helpful comment

@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

All 51 comments

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"

@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

@cdie I tried that and I got the following

PM> Install-Package Microsoft.EntityFrameworkCore.Tools.DotNet -Version 1.0.0-msbuild1-final -Pre
  GET https://api.nuget.org/v3/registration1-gz/microsoft.entityframeworkcore.tools.dotnet/index.json
  OK https://api.nuget.org/v3/registration1-gz/microsoft.entityframeworkcore.tools.dotnet/index.json 140ms
  GET https://www.myget.org/F/booker-core/auth/9038fb26-5b58-4125-a2f2-ec8327b318e6/api/v3/registration1/microsoft.entityframeworkcore.tools.dotnet/index.json
Restoring packages for C:\Development\AndroidAppAddictsApp\src\AndroidAppAddictsApp\AndroidAppAddictsApp.csproj...
Install-Package : Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.0-msbuild1-final' has a package type 'DotnetCliTool' that is not supported by project 'src\AndroidAppAddictsApp'.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Tools.DotNet -Version 1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Time Elapsed: 00:00:04.5577762****

@12michel34 I tried your link and this is what I get

PM> Add-Migration -Name CreateAppsSchema
The specified framework 'Microsoft.NETCore.App', version '1.1.0' was not found.
  - Check application dependencies and target a framework version installed at:
      C:\Program Files\dotnet\shared\Microsoft.NETCore.App
  - The following versions are installed:
      1.0.1
  - Alternatively, install the framework version '1.1.0'.
Process finished with non-zero exit code

@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

My problem as solved when i add in project.json
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-msbuild1-final"

@cdie Yep that did it. After installing that I could run the command successfully Add-Migration -Name CreateAppsSchema

@jrock2004 are we good to close this one now? I think everything you needed was captured in blog post? If not, let me know and we will add the missing info.

I want to check if command line still works.

@jrock2004 - If it is project.json based project then you need to change current directory to directory containing project.json file. Above error is also throw if dotnet cannot find project.json in current directory.

There won't be a project.json if this is VS2017. Just make sure to read the guidance in the blog post as you can't have both Package Manager Console and dotnet ef work in the same project for this release. Of course, you can add/remove the packages as needed to swap between the two. But if you are in VS, we would recommend using the Package Manager Console commands.

Is this the final decision with project.json ??? We just got used to it :(

@cdie Thx for the link, I installed VS 2017, new project - update nuget packages (to 1.1) - and it did not run after that... Though it's strange why it's not installed with VS.

@freerider7777 The problem is with VS 2017 generated projects no longer have a project.json file. If you generate via command line or yoeman generator you still get the project.json

@jrock2004 For sure yoeman does not know yet :)) Connect was just a couple of days ago. Why did Microsoft decide to get rid of project.json?

could not make dotnet ef to run... :(( VS 2017 windows 7...

@freerider7777 take a look at https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-tools-msbuild-alpha/ for info on why project.json is being retired. If you are still having issues with dotnet ef in VS2017 after following the guidance at the end of https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-entity-framework-core-1-1/, then open up a new issue.

@rowanmiller ok, thx..I've read everything. I see for now VS is rather loosey goosey :) dotnet ef not compatible with package manager comman line...

@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.).

@rowanmiller for you it's obvious, for us not... in VS code you just run npm start as in normal command line. Also the templates for project do not reference 1.1 packages - some work is yet to be done for VS to work 'out of the box' :)

@freerider7777 not disagreeing with you at all. The state of our tooling is very rough right now (especially for VS2017). I definitely didn't mean to imply that it should have been obvious... I still have to look at my own notes to work out what to use where sometimes 馃槷.

@rowanmiller Just to mention... we would complain anyway :))) Users are like that you know :) Thx for your efforts! the product is getting better and better.

FWIW I was also getting

Install-Package : Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.0-msbuild1-final' has a package type 'DotnetCliTool' that is not supported by project 'ProjectNameHere'

It should probably be noted on the efproject website that csproj project aren't supported / link to the workaround

@ScottRFrost the Package Manager Console commands work, but dotnet ef is not really working. See the last section of the announcement post for details (there is a section specifically about VS2017 RC) - https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-entity-framework-core-1-1/.

BTW you can't Install-Package on a CLI tools package (at least not yet). You need to manually edit the csproj.

I assume the UI will eventually have the ability to add the CLI tools? It's actually not a bad experience for as early / bleeding edge as this stuff is, but the documentation being out of data / based on project.json is what threw me off.

Any idea when the scaffolding tools will be able to work with stored procs?

@ScottRFrost yes, the tooling is still very much inflight and there are a lot of experience issues to iron out.

Stored procedure support is one of the bigger features on our top priority backlog, I don't have a specific answer for when we'll implement it... but it is on the short list of critical things on our Roadmap

Nightly Builds

If anyone wants to try out the nightly builds of the EFCore Tools for Visual Studio 2017 RC and .NET Core SDK Preview 3 (i.e. .csproj, not project.json) they can be found on the aspnetcore-feature-work feed. See NuGet's documentation for how to add a package source.

Your .csproj should look something like this.

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design">
      <Version>1.0.1</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
      <Version>1.0.0-*</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NETCore.App">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Sdk">
      <Version>1.0.0-alpha-20161104-2</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
      <Version>1.0.0-*</Version>
    </DotNetCliToolReference>
  </ItemGroup>

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

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\.runtimeconfig.json'
Process finished with non-zero exit code_

Any idea what I have to do?

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).

Howdy folks, if anyone is interested in trying out the next release of the EF tools, please see #7358.

I am having no luck whatsoever. I've got the very latest VS 2017 RC as of today. I created an ASP.NET Core Web API project. I changed the Core version to 1.1. These are my NuGet reference, pasted sstraight from the .csproj file:
Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0"
Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.0.1"
Microsoft.EntityFrameworkCore.Tools" Version="1.1.0-preview4-final"
Microsoft.NETCore.App" Version="1.0.1"
Microsoft.AspNetCore.Mvc" Version="1.0.1"
Microsoft.AspNetCore.Routing" Version="1.0.1"
Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.0"
Microsoft.AspNetCore.Server.Kestrel" Version="1.0.1"
Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.0"
Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.0"
Microsoft.Extensions.Configuration.Json" Version="1.0.0"
Microsoft.Extensions.Logging" Version="1.0.0"
Microsoft.Extensions.Logging.Console" Version="1.0.0"
Microsoft.Extensions.Logging.Debug" Version="1.0.0"
Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.0"

When I opened package manager and ran dbcontext scaffold "Server=myserver;Database=mydatabase;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Verbose
I got "scaffold-dbcontext dotnet exec needs a managed .dll or .exe extension". I've tried upgrading and downgrading various things. Restarting Visual Studio. Trying to install Microsoft.EntityFrameworkCore.Tools.DotNet (it says my project type is not correct).

If I try to run in command window or powershell, it tells me notnet-ef is not valid

I've got the latest version of Powershell. I've been through hundreds, if not thousands of posts, many of which refer to the old .json project files. Can somebody tell me, starting from a clean machine, how to get the scaffold command to work against a very plain database with 1 very plain table? I've tried absolutely everything I can think of. I'm out of ideas.

Thanks in advance

@MikeYeager Hi!
I just tested scaffolding with new project, please have a look what packages I've added:

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.NETCore.App" Version="1.1.0" />

and the command line (in Package Manager console in VS):

Scaffold-DbContext "Server=.database.windows.net;Initial Catalog=2017;Persist Security Info=False;User ID=login;Password=password" Microsoft.EntityFrameworkCore.SqlServer

works just fine

@MikeYeager See #7358 for what packages to install.

Thanks for the responses. I eventually found another computer I could install everything on (VS2017 RC, Docker, etc.) I managed to get everything to work there. It seems that no amount of uninstalling, reinstalling, repairing, etc. is able to fix my original dev machine. Something is hosed and even using -Verbose flags, etc. there is not much feedback about why it's failing. I'm going to chalk it up to V1, preview and RC build issues and assume it will be worked out in a few months when there is a release version of all of the pieces and parts.

@jrock2004 @MicahZoltu @MikeYeager @bricelam @WouterDeKort

when i going for db First approach in .net core with Entity Framework Core 1.0 its giving me this error
"Process finished with non-zero exit code" while i am executing Scaffold-DbContext

please help me out

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.

Thank you @MikeYeager my issue resolved.

Hi Rowan and all, I am a new student studying mvc and just going through tutorial with microsoft and stuck with the dreaded dotnet-ef using 2017 rc can anyone explain what to do error reads
c:\program files(x86) microsoft visual studio\2017\comunity>dotnet ef migrations add initial
no executable found matching command "dotnet-ef"

c:\program files(x86) microsoft visual studio\2017\comunity>dotnet ef database update
no executable found matching command "dotnet-ef" I am not sure if im puting correct info in command prompt as it reqests or doi go in to vs command prompt ??

@Br324 cd to the directory containing your *.csproj file before running dotnet ef.

Hi bricelam, Thanks for quick reply, But I am not sure how to do what you said I have only been using vs for a week, please find enclosed the screenshot of tutorial im working on, still unsure as to what to put in the command prompt or vs prompt and path to use could you scrrenshot how it looks and where it goes exactly thanks again Br324.
screenshot-docs microsoft com 2017-02-20 11-53-39

As @freerider7777 suggested I matched my packages with his reference set and it worked well.

For me the EF Core package itself was missing. I'm not sure why the Tools or SqlServer packages are not dependent on the main package to have it installed as a prerequisite

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />

For me the EF Core package itself was missing. I'm not sure why the Tools or SqlServer packages are not dependent on the main package to have it installed as a prerequisite
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />

SqlServer package is dependent on and will pull in core package. You do not need reference to it in your csproj.

May you explain where we would see Microsoft.EntityFrameworkCore being pulled in? Or where I can read on how that process works? I also thought I needed to add a reference to it in my csproj - but a warning symbol appears next to it...

I cannot write: "using Microsoft.EntityFrameworkCore" or access DbContext.

.Include( ) not returning relationships (from principal table to dependent table), or only returning one row of data:

http://stackoverflow.com/questions/43127957/fix-include-not-working-in-net-core-include-on-relationship-only-retur

@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));
        }

Also, in Startup.cs make sure you have this at the top:

using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using _**Project_Name_Here**_.Models;

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.

image

I migrated a VS2015 application with EF6.1.3 to VS2017 (net461), but I am not able to do migrations and update-database

image

@lincolnzocateli could you file an issue on https://github.com/aspnet/EntityFramework6

Yes, you can close this issue

Was this page helpful?
0 / 5 - 0 ratings