Originally reported on comments section of another issue by @christianrondeau
I could not find any solution or reference to a solution in #3925 - I am using
When I run (in the Package Manager Console)
> dotnet ef
[1m[31mNo executable found matching command "dotnet-ef"[39m[22m
Here's the dotnet
version:
> dotnet --version
1.0.0-preview1-002702
Here's the project.json
pieces that relate to EF:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-*",
"imports": "portable-net452+win81"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net452+win81"
]
}
},
I have installed Microsoft .NET Core 1.0.0 RC2 - VS 2015 Tooling Preview 1
and Microsoft .NET Core 1.0.0 RC2 - SDK Preview 1 (x64)
, I have fully uninstalled RC1
before and dotnet restore
works... I'm out of ideas.
I'm seeing this too. Note that running dotnet ef
via Powershell works fine, it's only in the VS Package Manager Console that it's not working.
I hit the same error. Then I changed the current directory to the one where project.json
was present and it works.
By default, VS PMC is at the root folder of solution and not the project. That would be the reason why it doesn't work for that particular case.
Ah, I missed that. You are using dotnet ef
in Package Manager Console? That's not really an intended thing to do since we have proper PowerShell commands that have much richer context on the project etc. than the command line tool. You would typically use Add-Migration
, Update-Database
, Scaffold-DbContext
etc. from Package Manager Console.
Too bad dotnet/NuGet don't support "global commands" yet (https://github.com/NuGet/Home/issues/1605). DotNet CLI can only resolve "dotnet-ef" when it is within the project directory. This is something EF can't do anything about.
Thanks @rowanmiller, I confirm that I indeed can run dotnet ef
when outside of the Package Manager Console
. I understand that you can't even display a helpful error message, since your code doesn't even get called. dotnet
however still responds in the Package Manager Console
, so maybe something can be done there to either give a helpful message _or_ make it work there too? It's a very convenient place to run project-related commands :)
you can't even display a helpful error message, since your code doesn't even get called.
@christianrondeau bingo. We'd need changes to dotnet, NuGet, or VS to make this easier to use. Potential feature requests that may help: https://github.com/dotnet/cli/issues/917, https://github.com/dotnet/cli/issues/2939, NuGet/Home#1605
so maybe something can be done there to either give a helpful message or make it work there too? It's a very convenient place to run project-related commands :)
It should work if you cd
into the project directory within Package Manager Console. The error is because PMC is at the solution directory by default. Though you will hit a rough edge where PMC will report an error even though the command executes correctly.
If you have PMC, is there a reason you would use dotnet ef
over the PowerShell commands?
Closing as there isn't really anything we can do here. dotnet
commands need to be invoked in the directory for the project that the command is registered in. Happy to keep discussing on this thread though.
@natemcmaster thanks for the issue links!
@rowanmiller the reason I'm using "dotnet ef" instead of PowerShell commands in PMC is simply because I don't know better yet :P I'm following guides and tutorials to learn ASP.Net Core and EF7 together, so since I usually ran FluentMigrator in PMC, and dotnet
worked there, I assumed dotnet ef
would too.
Oh and I confirm it does work when entering the project directory. I think it didn't work before (same error message) because I was missing the EF tools package.
But Default project
is set to right one.
Who does not use that to provide a path? dotnet? PMC? ef?
But Default project is set to right one. Who does not use that to provide a path? dotnet? PMC? ef?
The PowerShell commands make use that setting - since they have access to all the extra context of PMC. I can see the logic in saying that the dropdown should control the working directory of PMC - though I can also see the logic that says the working directory is at the solution directory. If this were to change, it would be a NuGet change - https://github.com/NuGet/Home.
@rowanmiller Fine lets continue talk here:
I created a default asp.net core .NET Core project with user authentication.
When I am inside the project dir on the CMD and do:
dotnet ef migrations add init
I get the error you see in the screenshot.
How can this be?
You forgot to type "ef" http://ef.readthedocs.io/en/latest/miscellaneous/cli/dotnet.html
I'm trying to get this to work on Mac, I tried the same instructions but I still get "No executable found matching command "dotnet-ef", even when I'm within the directory for thre project. Any suggestions ? or maybe some extra steps are required for Mac ?
I confirm that it works for me now, I just forgot to add in my project.json:
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"}
@ErikEJ Thanks with DNXCore50 it worked!
I just got a problem with this today and have been scaffolding a zillion times before without a problem.
I am using "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview3-22299" with dotnet core version 1.1.0-alpha1-*.
The error I get is:
dotnet : No executable found matching command "dotnet-ef"
Any ideas?
I ran this from the command-line to get it to work again:
Install-Package Microsoft.EntityFrameworkCore.Tools.DotNet -Version 1.0.0-preview3-22299
It seems as the dotnet tools got corrupted for some reason that the dotnet restore couldnt resolve. I tried to clear the package cache etc before I ran the above. After I reinstalled the package dotnet crashed and after that it has begun to work again.
To anyone targeting EF Core 1.1 who might be wondering why @johanskoldekrans's solution worked, be sure to read the "Upgrading to 1.1" section in the EF Core 1.1 release announcement blog post.
As of EF Core 1.1, the EF Core tools package is now Microsoft.EntityFrameworkCore.Tools.DotNet
rather than Microsoft.EntityFrameworkCore.Tools
. You'll also want to be using version 1.1.0-preview4
.
Changing the package name to Microsoft.EntityFrameworkCore.Tools.DotNet as @benjamincburns mentioned finally did the trick. Thank you!
@benjamincburns LIFE SAVER THANKS MAN !
@benjamincburns Nailed it! Thanks 馃憤
Using Package Manager Console within Visual Studio 2017 RTM, you must first run a CD and be inside the project root folder.
After that you'll get all PS/DOS commands from dotnet ef
cli
Has anyone been able to make this work on the GA version of Visual Studio 2017 for Mac? I keep getting message Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.1' has a package type 'DotnetCliTool' that is not supported by project 'EFGetStarted.AspNetCore.NewDb'. when I try to add Microsoft.EntityFrameworkCore.Tools.DotNet, version 1.0.1.
@reynjoz I get the same error. It can be an error in Visual Studio for Mac. I couldn't find the way to handle database in VS for MAC.
@reynjoz I found the solution.
stackoverflow_link
Kindly help me. I just created demo project on my MAC and error appear.
@hkumipig - Few questions.
If above does not fix the problem then share your directory structure and csproj file please.
@smitpatel Thank you for your response
Yes already run the dontnet restore "Packages successfully restored."
Already answered to @hkumipig in a different thread.
For others, if you are using VS for Mac then you would need to run dotnet restore
on command line manually. Even though VS for Mac says packages restored successfully it does not restore DotNetCliToolReference properly.
Tracking external issue https://developercommunity.visualstudio.com/content/problem/198601/vs-restore-function-not-the-same-as-cli-when-resto.html
Most helpful comment
Ah, I missed that. You are using
dotnet ef
in Package Manager Console? That's not really an intended thing to do since we have proper PowerShell commands that have much richer context on the project etc. than the command line tool. You would typically useAdd-Migration
,Update-Database
,Scaffold-DbContext
etc. from Package Manager Console.