"No executable found matching command "dotnet-ef""
"No executable found matching command "dotnet-ef""
我正在尝试使用 this tutorial:
学习 ASP.NET 核心的基础知识
- 我已经创建了一个 ASP.NET 核心网络应用程序
- 我已经使用 here
中的说明对其进行了升级
现在,我正在尝试在项目文件夹(project.json 所在的位置)的命令提示符下使用 dotnet ef migrations add Initial
设置数据库迁移:
No executable found matching command "dotnet-ef"
我已经更改了 project.json,因此 dotnet-ef 可以工作:
"tools": {
...
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
现在,生成失败并出现以下错误:
The specified framework 'Microsoft.NETCore.App', version
'1.0.0-rc2-3002702' was not found.
- Check application dependencies and target a framework version installed at:
C:\Program Files\dotnet\shared\Microsoft.NETCore.App
- The following versions are installed:
1.0.0
1.0.1
1.1.0
- Alternatively, install the framework version '1.0.0-rc2-3002702'
好的,这是有道理的,因为 Microsoft.EntityFrameworkCore.Tools 1.0.0-preview1-final 依赖于错误中提到的旧版本,如在 project.lock.json 文件中找到的那样。
我不想降级,所以我放了最新版本的 Microsoft.EntityFrameworkCore.Tools 我能找到:
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0-preview4-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
这样做会导致同样的错误:
No executable found matching command "dotnet-ef"
如何让它在 1.1 版中运行?
其他可能有用的上下文信息:
OS: Windows 7 x64
VS:2015 社区版
来自 project.json 的其他部分:
"frameworks": {
"netcoreapp1.1": {
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"runtimes": {
"win7-x64": {}
},
EntityFrameworkCore 1.1.0-preview4-final 仅适用于 asp.net 核心 1.1,如果您想从核心 1.0 转移到核心 1.1,请查看 https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-1-1/。
更新 [30/3/2017]
新包是
Install-Package Microsoft.EntityFrameworkCore.Tools
原版
尝试添加
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
}
此外,这里还有一个关于使用 EF Core 1.1.0 设置 .Net Core 1.1.0 的教程
https://docs.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite
Grierson
的答案还可以,但为了以后参考,我将包括整个过程,直到我让它起作用:
1) Tools.DotNet 已在接受的答案中提出
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
}
运行 收到相同命令:
Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed. Install the version of that package that matches the installed version of Microsoft.EntityFrameworkCore and try again.
2) 添加了
//EF Core
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
}
3) 现在,错误是:
No parameterless constructor was found on 'ApplicationDbContext'.
Either add a parameterless constructor to 'Application DbContext' or
add an implementation of 'IDbContextFactory' in
the same assembly as 'ApplicationDbC ontext'.
我选择了实现接口。一种可能的方式:
public ApplicationDbContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseSqlServer("Server=(localdb)\mssqllocaldb;Database=Movies;Trusted_Connection=True;MultipleActiveResultSets=true");
return new ApplicationDbContext(builder.Options);
}
运行dotnet ef migrations add Initial
时出现同样的错误
4) 我为 ApplicationDbContext
class
添加了默认构造函数
现在我可以添加迁移了。
我遇到了同样的问题。
我已经解决了
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
},
您可能会错过 CliToolReference
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
我正在尝试使用 this tutorial:
学习 ASP.NET 核心的基础知识- 我已经创建了一个 ASP.NET 核心网络应用程序
- 我已经使用 here 中的说明对其进行了升级
现在,我正在尝试在项目文件夹(project.json 所在的位置)的命令提示符下使用 dotnet ef migrations add Initial
设置数据库迁移:
No executable found matching command "dotnet-ef"
我已经更改了 project.json,因此 dotnet-ef 可以工作:
"tools": {
...
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
现在,生成失败并出现以下错误:
The specified framework 'Microsoft.NETCore.App', version '1.0.0-rc2-3002702' was not found. - Check application dependencies and target a framework version installed at: C:\Program Files\dotnet\shared\Microsoft.NETCore.App - The following versions are installed: 1.0.0 1.0.1 1.1.0 - Alternatively, install the framework version '1.0.0-rc2-3002702'
好的,这是有道理的,因为 Microsoft.EntityFrameworkCore.Tools 1.0.0-preview1-final 依赖于错误中提到的旧版本,如在 project.lock.json 文件中找到的那样。
我不想降级,所以我放了最新版本的 Microsoft.EntityFrameworkCore.Tools 我能找到:
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0-preview4-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
这样做会导致同样的错误:
No executable found matching command "dotnet-ef"
如何让它在 1.1 版中运行?
其他可能有用的上下文信息:
OS: Windows 7 x64 VS:2015 社区版 来自 project.json 的其他部分:
"frameworks": {
"netcoreapp1.1": {
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"runtimes": {
"win7-x64": {}
},
EntityFrameworkCore 1.1.0-preview4-final 仅适用于 asp.net 核心 1.1,如果您想从核心 1.0 转移到核心 1.1,请查看 https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-1-1/。
更新 [30/3/2017]
新包是
Install-Package Microsoft.EntityFrameworkCore.Tools
原版
尝试添加
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
}
此外,这里还有一个关于使用 EF Core 1.1.0 设置 .Net Core 1.1.0 的教程
https://docs.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite
Grierson
的答案还可以,但为了以后参考,我将包括整个过程,直到我让它起作用:
1) Tools.DotNet 已在接受的答案中提出
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
}
运行 收到相同命令:
Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed. Install the version of that package that matches the installed version of Microsoft.EntityFrameworkCore and try again.
2) 添加了
//EF Core
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
}
3) 现在,错误是:
No parameterless constructor was found on 'ApplicationDbContext'. Either add a parameterless constructor to 'Application DbContext' or add an implementation of 'IDbContextFactory' in the same assembly as 'ApplicationDbC ontext'.
我选择了实现接口。一种可能的方式:
public ApplicationDbContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseSqlServer("Server=(localdb)\mssqllocaldb;Database=Movies;Trusted_Connection=True;MultipleActiveResultSets=true");
return new ApplicationDbContext(builder.Options);
}
运行dotnet ef migrations add Initial
4) 我为 ApplicationDbContext
class
现在我可以添加迁移了。
我遇到了同样的问题。
我已经解决了
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
},
您可能会错过 CliToolReference
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>