No executable found matching command "dotnet-ef"
I'm doing a project sample by using ASP.Net Core RC2 with Microsoft.EntityFramework.Core
and SQLite.
I've followed this tutorial: https://damienbod.com/2015/08/30/asp-net-5-with-sqlite-and-entity-framework-7/
But, when I run this command :
dotnet ef migrations add FirstMigration
I got this error :
No executable found matching command "dotnet-ef"
Here is my project.json
configuration:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Solution 1:
Entity Framework Core 1.0
You should just need to update the tools
section of your project.json file to include this:
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
This should make the dotnet ef
commands available.
Important
I should also note here that the dotnet ef
commands will only be available when running them from the same directory which contains the project.json file.
Entity Framework Core 1.1
If you are having this problem again after upgrading to Entity Framework Core 1.1, be sure to replace the Microsoft.EntityFrameworkCore.Tools
dependency with Microsoft.EntityFrameworkCore.Tools.DotNet
version 1.1.0-preview4
. There is no need to keep the imports
section, either. For more information on this, see the "Upgrading to 1.1" heading under the Entity Framework Core 1.1 release announcement blog post.
Solution 2:
Entity Framework Core 1.1
Adding in on this if you're using VS2017 with the new .csproj projects without a project.json file
you need to edit the .csproj file (right click it in solution explorer and click edit whatever.csproj) and then paste this in
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
<Version>1.0.0-*</Version>
</DotNetCliToolReference>
</ItemGroup>
courtesy of : https://github.com/aspnet/EntityFramework/issues/7358#issuecomment-278379967
Solution 3:
Specific to VS2017 15.3 or greater and ASP.NET CORE 2.0 or later...
Install nuget for db provider via command line or nuget package manager.
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
Add following section to .csproj
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
Version="2.0.0" />
</ItemGroup>
Install design time tools via commandline or nuget manager in VS2017.
dotnet add package Microsoft.EntityFrameworkCore.Design
This enables dotnet ef * at the command line in the project directory.
Enables dotnet ef * commands at the command line in the project directory,
dotnet ef migrations add Initial
dotnet ef database update Initial
dotnet ef dbcontext scaffold
Solution 4:
This is a common issue when switching from .NET Core 1.0 to .NET Core 1.1+ or 2.x.
To fix that, you need to:
- Get the Microsoft.EntityFrameworkCore.Tools and Microsoft.EntityFrameworkCore.Tools.DotNet package libraries using NuGet.
- Manually add a reference to this package within your
project.json
(for .NET Core 1.0) or<projectName>.csproj
(for .NET Core 1.1+ & 2.x) project configuration file.
More specifically, for .NET Core 1.0 projects, add this:
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0"
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0"
}
For .NET Core 1.1+ and .NET Core 2.x projects, add this:
<ItemGroup>
<DotNetCliToolReference
Include="Microsoft.EntityFrameworkCore.Tools"
Version="2.0.0" />
<DotNetCliToolReference
Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
Version="2.0.0" />
</ItemGroup>
If you already have a tools
json key or an <ItemGroup>
element with one or more existing DotNetCliToolReference
elements, just add the new ones to the existing group.
IMPORTANT: other than performing the above steps, you have to launch the dotnet ef
command within the project root folder (the one containing the project file), otherwise it won't work.
For additional info and an extensive explanation of the issue you can read more on my blog post.