efcore icon indicating copy to clipboard operation
efcore copied to clipboard

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

Open mehtanilay10 opened this issue 9 years ago • 47 comments

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

mehtanilay10 avatar Jun 28 '17 16:06 mehtanilay10

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

bricelam avatar Jun 28 '17 16:06 bricelam

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

mehtanilay10 avatar Jun 28 '17 16:06 mehtanilay10

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

mehtanilay10 avatar Jun 28 '17 16:06 mehtanilay10

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

smitpatel avatar Jun 28 '17 16:06 smitpatel

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

smitpatel avatar Jun 28 '17 16:06 smitpatel

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

mehtanilay10 avatar Jun 28 '17 16:06 mehtanilay10

Does running dotnet build pass?

smitpatel avatar Jun 28 '17 16:06 smitpatel

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

mehtanilay10 avatar Jun 28 '17 16:06 mehtanilay10

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

bricelam avatar Jun 28 '17 17:06 bricelam

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

bricelam avatar Jun 28 '17 17:06 bricelam

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

bricelam avatar Jun 28 '17 17:06 bricelam

.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 avatar Jun 28 '17 17:06 mehtanilay10

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

mehtanilay10 avatar Jun 28 '17 17:06 mehtanilay10

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 https://github.com/NuGet/NuGet.Client/pull/1495 and I could not find where AssetTargetFallBack is set.

smitpatel avatar Jun 28 '17 17:06 smitpatel

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

mehtanilay10 avatar Jun 28 '17 17:06 mehtanilay10

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.

smitpatel avatar Jun 28 '17 17:06 smitpatel

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" />

timpur avatar Sep 04 '17 01:09 timpur

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.

JeanVanDenderFlume avatar Sep 10 '17 08:09 JeanVanDenderFlume

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>

AliBayatGH avatar Oct 05 '17 19:10 AliBayatGH

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" />

veneMarcos avatar Oct 31 '17 22:10 veneMarcos