No executable found matching command "dotnet-ef" even after adding CLI
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
Ensure...
- You're using the .NET Core SDK 2.0
- You ran
dotnet restoreon the project - You
cded to the project's (*.csproj) directory
Yes, i am using 2.0 SDK and tried for dotnet restored on project but still got same error.
I am uploaded entire solution on github. CodeFirst is a project, which i want to Migrate and generate error. https://github.com/mehtanilay10/EntityFrameworkCore
Align your package versions. Either use preview1 packages or preview2. Mix of those are not supported.
Also to use dotnet ef correctly, you need to install Microsoft.EntityFrameworkCore.Design package.
Added Microsoft.EntityFrameworkCore.Design and also change all to packages to preview1 still facing same error!
Does running dotnet build pass?
yes, project build successfully. But gives only error for CLI
...and you're certain dir lists your *.csproj and dotnet --info says 2.0.0?
(I know these are stupid questions, but I honestly have no idea what could be going wrong.)
You may need to follow up on dotnet/cli. Something is going wrong before the EF code gets a chance to run.
.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
If you want to check on my machine then i will give remote access, so you can see what's going wrong.
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 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.
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.
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" />
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
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.
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>
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" />