Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No executable found matching command "dotnet-ef" even after adding CLI #8996

Closed
mehtanilay10 opened this issue Jun 28, 2017 · 47 comments
Closed
Labels
closed-no-further-action The issue is closed and no further action is planned.

Comments

@mehtanilay10
Copy link

I want to Migrate my Database with Models. I am using EF Core 2.0 Preview.

dotnet ef migrations add InitialCreate
dotnet : No executable found matching command "dotnet-ef"

Packahe & Tools

I am already added all CLI and PM but still got error!

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0-preview2-final" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview1-final" />
	<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview1-final" />
  </ItemGroup>

Further technical details

EF Core version: 2.0 Preview
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 15063.0
IDE: Visual Studio 2017 Preview

@bricelam
Copy link
Contributor

bricelam commented Jun 28, 2017

Ensure...

  1. You're using the .NET Core SDK 2.0
  2. You ran dotnet restore on the project
  3. You cded to the project's (*.csproj) directory

@mehtanilay10
Copy link
Author

Yes, i am using 2.0 SDK and tried for dotnet restored on project but still got same error.

@mehtanilay10
Copy link
Author

I am uploaded entire solution on github. CodeFirst is a project, which i want to Migrate and generate error.
https://github.com/mehtanilay10/EntityFrameworkCore

@smitpatel
Copy link
Member

Align your package versions.
Either use preview1 packages or preview2. Mix of those are not supported.

@smitpatel
Copy link
Member

Also to use dotnet ef correctly, you need to install Microsoft.EntityFrameworkCore.Design package.

@mehtanilay10
Copy link
Author

Added Microsoft.EntityFrameworkCore.Design and also change all to packages to preview1 still facing same error!

@smitpatel
Copy link
Member

Does running dotnet build pass?

@mehtanilay10
Copy link
Author

mehtanilay10 commented Jun 28, 2017

yes, project build successfully. But gives only error for CLI

@bricelam
Copy link
Contributor

...and you're certain dir lists your *.csproj and dotnet --info says 2.0.0?

@bricelam
Copy link
Contributor

(I know these are stupid questions, but I honestly have no idea what could be going wrong.)

@bricelam
Copy link
Contributor

You may need to follow up on dotnet/cli. Something is going wrong before the EF code gets a chance to run.

@mehtanilay10
Copy link
Author

.NET Command Line Tools (2.0.0-preview1-005977)

Product Information:
Version:            2.0.0-preview1-005977
Commit SHA-1 hash:  414cab8a0b

Runtime Environment:
OS Name:     Windows
OS Version:  10.0.15063
OS Platform: Windows
RID:         win10-x64
Base Path:   C:\Program Files\dotnet\sdk\2.0.0-preview1-005977\
Microsoft .NET Core Shared Framework Host
Version  : 2.0.0-preview1-002111-00
Build    : 1ff021936263d492539399688f46fd3827169983

@mehtanilay10
Copy link
Author

If you want to check on my machine then i will give remote access, so you can see what's going wrong.

@smitpatel
Copy link
Member

smitpatel commented Jun 28, 2017

I cloned the repo posted.
Updated the CodeFirst.csproj as follows.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
    <UserSecretsId>aspnet-CodeFirst-DB7142CA-3EB8-4FB3-9C4A-0173586B87FB</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0-preview1-final" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview1-final" />
	<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview1-final" />
  </ItemGroup>

</Project>

In the directory D:\EntityFrameworkCore\EntityFramework\CodeFirst
dotnet restore
dotnet ef
and it worked.

I had to remove PackageTargetFallback due to this NuGet/NuGet.Client#1495 and I could not find where AssetTargetFallBack is set.

@mehtanilay10
Copy link
Author

@smitpatel Thanks a lot for solving this issue ;)
Finally it was removed error from CMD but when i am using package manager in VS 2017 15.3 it gives same error. May be this is VS's Issue.

@smitpatel
Copy link
Member

smitpatel commented Jun 28, 2017

By default Package Manager Console (PMC) is rooted at dir containing the solution file.
dotnet ef requires to be operated in directory containing csproj file. The only way to invoke dotnet ef in PMC, you need to manually cd into the correct folder where your csproj file is located. Changing anything else in PMC has no effect current directory.

For best user experience, use PMC commands for EF (Add-Migration & friends) in PMC.

@timpur
Copy link

timpur commented Sep 4, 2017

I has this issue and like to share.

i had the Microsoft.EntityFrameworkCore.Tools.DotNet as <PackageReference> because i uesd the GUI package manager to install it.

when i changed it to <DotNetCliToolReference> and then dotnet restore, this fixed it.

eg Use:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
Not
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />

@JeanVanDenderFlume
Copy link

JeanVanDenderFlume commented Sep 10, 2017

That last thing worked for me
In my case i had to change both \library-management\LibraryData\LibraryData.csproj and \library-management\Library\Library.csproj from to

My God, this library mangement is from github, orginally a core 1.1 web app I hope realy with 2.0 and webpack things will be stable and change too much.

@AliBayatGH
Copy link

AliBayatGH commented Oct 5, 2017

This worked for me:
The EF tools for the CLI are provided in Microsoft.EntityFrameworkCore.Tools.DotNet. To install this package, add it to the DotNetCliToolReference collection in the .csproj file, You have to install this package by editing the .csproj file; you can't use the install-package command or the package manager GUI. You can edit the .csproj file by right-clicking the project name in Solution Explorer and selecting Edit XXX.csproj.


<ItemGroup>
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
  <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>

@veneMarcos
Copy link

veneMarcos commented Oct 31, 2017

I hade the some trouble and I fix this change the Microsoft.EntityFramework.Tools.Dotnet from the First <ItemGroup> like this:

 <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />

For a second <ItemGroup> tag represent the DotNetCliToolReference:

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />

@huoxudong125
Copy link

huoxudong125 commented Nov 22, 2017

It's a pity for new one(.net core user).

dotnet : 未找到与命令“dotnet-ef”匹配的可执行文件

.NET 命令行工具 (2.0.3)

Product Information:
 Version:            2.0.3
 Commit SHA-1 hash:  12f0c7efcc

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.3\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.3
  Build    : a9190d4a75f4a982ae4b4fa8d1a24526566c69df

in powershell dotnet ef throw new exception:

Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute' from assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Is there is a simple way to use this commands or have a good tutorial?

@amazingankur
Copy link

I have just started playing with .Net Core. I am running into issues with
dotnet ef migrations add Initial. I am using Docker for sql server but when I run the command I get following error: Specify which project file to use because this contains more than one project file.
When I remove docker-compose.dcproj, it runs fine but sql server migration generates exception as it doesn't get docker to instantiate DataContext.
On contrary, if I remove *.csproj, it says no executable found matching command.
Need help!

@amazingankur
Copy link

Stack trace as below:
An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: Cannot resolve scoped service 'SportsStore.Models.DataContext' from root provider.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'DataContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'DataContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time. ---> System.MissingMethodException: No parameterless constructor defined for this object.

@jlenriquez
Copy link

@amazingankur Where you able to solve your problem? In any case you still have issues with IDesignTimeDbContextFactory, make sure your DataContext class has a default constructor with no parameters in it. The migration script uses the parameterless constructor during execution.

@TLBSoftware
Copy link

I experienced this issue as well

Just like what @AliBayatGH @veneMarcos @timpur mentioned it appears as if the
dotnet add package Microsoft.EntityFrameworkCore.Tools.DotNet
command is adding the package as a PackageReference to the 2nd Item group in *.csproj. When this package is moved to the 3rd item group and the tag changed to "DotNetCliToolReference" the problem is solved.

@jlenriquez
Copy link

To those who may stumble this page looking for answers I have provided codes here in github that can be cloned: https://github.com/jlenriquez/SpikeSQLiteEF_OSX

The sample code can be run step-by-step by commenting/uncommenting necessary steps and can be used as learning reference.

@bricelam
Copy link
Contributor

The EF Core .NET Command-line Tools docs may also be helpful.

@josephkandi
Copy link

I fixed this by adding this to my <Project Name>.csproj file

<ItemGroup>   
 <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />   
 <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> 
</ItemGroup>

This line was already there, <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" /> . I only added the second line.

After that then restore the packages by running dotnet restore

@tttrrryyyyeer
Copy link

tttrrryyyyeer commented Mar 25, 2018

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
  </ItemGroup>

@ravensorb
Copy link

I followed this thread and am getting the following

Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingProviderCodeGenerator' while attempting to activate 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator'.

Any thoughts?

@smitpatel
Copy link
Member

@ravensorb - You are mixing packages from 2.0 & 2.1 release. Please make sure all packages from EF Core are on same release cycle include EFCore.Tools

@plasticalligator
Copy link

plasticalligator commented Apr 19, 2018

This is how I feel about having to install multiple NuGet packages and then manually modify my project configuration file to get the EF toolset, only usable by console, with no UI integration within Visual Studio.

@JonatanWang
Copy link

JonatanWang commented Jun 2, 2018

Go to the folder where .csproj is and run “dotnet restore" first

@rodrigorf
Copy link

Expliciting changing to my csproj folder and running "dotnet restore" worked for me. First i confirmed if my PackageReference and DotNetCliToolReference were correct, i had two add two missing references. Thks

@DongLei-tw
Copy link

you might miss the CliToolReference references:

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />  
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /></ItemGroup>

@webhay
Copy link

webhay commented Mar 23, 2019

I have done something worked for me:
1- First dotnet publish your app.
2- Change the execute permission on the .dll in my case I have done: chmod 777 filename.dll
3- Use nano to remove the .sh script \n\r from all the lines.
It should work or might work :)

@imclint21
Copy link

imclint21 commented May 7, 2019

After adding this :

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
  </ItemGroup>

It works !

clintm@clint ~/l/Librum> dotnet ef

                     _/\__
               ---==/    \\
         ___  ___   |.    \|\
        | __|| __|  |  )   \\\
        | _| | _|   \_/ |  //|\\
        |___||_|       /   \\\/\\

Entity Framework Core .NET Command Line Tools 2.0.0-rtm-26452

@oising
Copy link

oising commented Jun 21, 2019

My problem was that my dotnet executable was the 3.0.0-preview version, but the EF project that had the design package installed in it was 2.2. So, I dropped a global.json into the solution root to force 2.2 and then dotnet ef worked from the root of the solution. I didn't even need to be in the project that had the NuGet package.

@aswanevelder
Copy link

@oising was the answer for me, using 3.0.0-preview but creating 2.2 projects.

dotnet new globaljson --sdk-version 2.2.204

@TomasHubelbauer
Copy link

TomasHubelbauer commented Sep 24, 2019

I'm using the newly released .NET Core 3.0 with packages in the CSPROJ all being 3.0 but dotnet ef doesn't work for me.

Edit: to @bricelam's answer below, I found documentation for this in https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#ef-core-3x.

@bricelam
Copy link
Contributor

dotnet tool install -g dotnet-ef

@dinob68
Copy link

dinob68 commented Oct 1, 2019

Also to use dotnet ef correctly, you need to install Microsoft.EntityFrameworkCore.Design package.

I have that and all above and still have no dotnet ef option when I do dotnet -h and get same error when I issue dotnet ef

@dinob68
Copy link

dinob68 commented Oct 1, 2019

dotnet tool install -g dotnet-ef

None of the above worked. Here is my proj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\OdeToFoodCore.Core\OdeToFoodCore.Core.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.4" />  
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
</Project>

after I run dotnet tool install -g dotnet-ef, like:

dinob @ /Users/dinob/Desktop/mywork/csharp/aspcore/OdeToFoodCore/OdeToFoodCore.Data 
 ~~ dotnet tool install -g dotnet-ef

You can invoke the tool using the following command: dotnet-ef
Tool 'dotnet-ef' (version '3.0.0') was successfully installed.

I still see no ef tool when I run dotnet -h

dinob @ /Users/dinob/Desktop/mywork/csharp/aspcore/OdeToFoodCore/OdeToFoodCore.Data 
 ~~ dotnet -h

.NET Core SDK (3.0.100)
Usage: dotnet [runtime-options] [path-to-application] [arguments]

Execute a .NET Core application.

runtime-options:
  --additionalprobingpath <path>   Path containing probing policy and assemblies to probe for.
  --additional-deps <path>         Path to additional deps.json file.
  --fx-version <version>           Version of the installed Shared Framework to use to run the application.
  --roll-forward <setting>         Roll forward to framework version  (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable).

path-to-application:
  The path to an application .dll file to execute.

Usage: dotnet [sdk-options] [command] [command-options] [arguments]

Execute a .NET Core SDK command.

sdk-options:
  -d|--diagnostics  Enable diagnostic output.
  -h|--help         Show command line help.
  --info            Display .NET Core information.
  --list-runtimes   Display the installed runtimes.
  --list-sdks       Display the installed SDKs.
  --version         Display .NET Core SDK version in use.

SDK commands:
  add               Add a package or reference to a .NET project.
  build             Build a .NET project.
  build-server      Interact with servers started by a build.
  clean             Clean build outputs of a .NET project.
  help              Show command line help.
  list              List project references of a .NET project.
  msbuild           Run Microsoft Build Engine (MSBuild) commands.
  new               Create a new .NET project or file.
  nuget             Provides additional NuGet commands.
  pack              Create a NuGet package.
  publish           Publish a .NET project for deployment.
  remove            Remove a package or reference from a .NET project.
  restore           Restore dependencies specified in a .NET project.
  run               Build and run a .NET project output.
  sln               Modify Visual Studio solution files.
  store             Store the specified assemblies in the runtime package store.
  test              Run unit tests using the test runner specified in a .NET project.
  tool              Install or manage tools that extend the .NET experience.
  vstest            Run Microsoft Test Engine (VSTest) commands.

Additional commands from bundled tools:
  dev-certs         Create and manage development certificates.
  fsi               Start F# Interactive / execute F# scripts.
  sql-cache         SQL Server cache command-line tools.
  user-secrets      Manage development user secrets.
  watch             Start a file watcher that runs a command when files change.

Run 'dotnet [command] --help' for more information on a command.

However, issuing dotnet ef shows the screen

dinob @ /Users/dinob/Desktop/mywork/csharp/aspcore/OdeToFoodCore/OdeToFoodCore.Data 
 ~~ dotnet ef


                     _/\__       
               ---==/    \\      
         ___  ___   |.    \|\    
        | __|| __|  |  )   \\\   
        | _| | _|   \_/ |  //|\\ 
        |___||_|       /   \\\/\\

Entity Framework Core .NET Command-line Tools 3.0.0

Usage: dotnet ef [options] [command]

Options:
  --version        Show version information
  -h|--help        Show help information
  -v|--verbose     Show verbose output.
  --no-color       Don't colorize output.
  --prefix-output  Prefix output with level.

Commands:
  database    Commands to manage the database.
  dbcontext   Commands to manage DbContext types.
  migrations  Commands to manage migrations.

Use "dotnet ef [command] --help" for more information about a command.

Having said that, I am not sure this is good solution, shouldn't ef tool be in project folder version rather than global version?

@smitpatel
Copy link
Member

@dinob68 - I am not able to understand why would dotnet -h would show anything EF specific.

@bricelam
Copy link
Contributor

bricelam commented Oct 2, 2019

dotnet tool list will show the tools you’ve installed

@bricelam
Copy link
Contributor

bricelam commented Oct 2, 2019

@dinob68 Think of it like a test runner. You don’t need to use an exact version of the runner or use a specific version of the testing framework. One runner will work with multiple versions of the test framework, and more than one version of the runner can be used with the same framework.

@Rafael955
Copy link

dotnet tool install -g dotnet-ef

This worked for me, thanks.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Projects
None yet
Development

No branches or pull requests