Microsoft.EntityFrameworkCore.Tools未安装,ASP.net核心
问题描述:
我正在创建一个简单的控制台应用程序(.Net Core)应用程序,其中我定义了一个名为fruit的类和一个名为FruitDbContext的dbcontext。本例中我使用了VS2015和SQL Server。Microsoft.EntityFrameworkCore.Tools未安装,ASP.net核心
我希望vs2015能为我创建数据库(代码第一次迁移?)。我已经安装了Package EntityFrameworkCore及其工具,然后使用Add-Migration for vs2015来创建数据库。我的sqlserver是本地安装的,所以没有网络问题。添加迁移遇到一个奇怪的Microsoft.EntityFrameworkCore.Tools安装成功时未安装。
PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer
Retrieving package 'Microsoft.EntityFrameworkCore.SqlServer 1.1.1' from 'nuget.org'.
GET https://www.nuget.org/api/v2/Packages(Id='Microsoft.EntityFrameworkCore.SqlServer',Version='1.1.1')
OK https://www.nuget.org/api/v2/Packages(Id='Microsoft.EntityFrameworkCore.SqlServer',Version='1.1.1') 43ms
GET https://www.nuget.org/api/v2/package/Microsoft.EntityFrameworkCore.SqlServer/1.1.1
OK https://www.nuget.org/api/v2/package/Microsoft.EntityFrameworkCore.SqlServer/1.1.1 103ms
Installing Microsoft.EntityFrameworkCore.SqlServer 1.1.1.
Installing NuGet package Microsoft.EntityFrameworkCore.SqlServer.1.1.1.
Successfully installed 'Microsoft.EntityFrameworkCore.SqlServer 1.1.1' to ConsoleApp1
Executing nuget actions took 1.01 sec
Time Elapsed: 00:00:01.3928695
PM> Install-Package microsoft.EntityFrameworkCore.Tools
Retrieving package 'Microsoft.EntityFrameworkCore.Tools 1.1.0' from 'nuget.org'.
GET https://www.nuget.org/api/v2/Packages(Id='Microsoft.EntityFrameworkCore.Tools',Version='1.1.0')
OK https://www.nuget.org/api/v2/Packages(Id='Microsoft.EntityFrameworkCore.Tools',Version='1.1.0') 79ms
GET https://www.nuget.org/api/v2/package/Microsoft.EntityFrameworkCore.Tools/1.1.0
OK https://www.nuget.org/api/v2/package/Microsoft.EntityFrameworkCore.Tools/1.1.0 105ms
Installing Microsoft.EntityFrameworkCore.Tools 1.1.0.
Installing NuGet package Microsoft.EntityFrameworkCore.Tools.1.1.0.
Successfully installed 'Microsoft.EntityFrameworkCore.Tools 1.1.0' to ConsoleApp1
Executing nuget actions took 554.65 ms
Time Elapsed: 00:00:00.8128143
PM> Add-Migration InitialMigration
Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project 'src\ConsoleApp1'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.
我的JSON文件
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.1",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
我试图恢复包,重建项目,但什么也没有帮助。
这是我的项目的结构表明,我没有做什么花哨
我的类一样简单,因为他们可能是:
Fruit.cs
namespace ConsoleApp1.Entity
{
public class Fruit
{
public string ID { get; set; }
public string FruitName { get; set; }
public string FruitColor { get; set; }
}
}
FruitDbContext.cs
using Microsoft.EntityFrameworkCore;
namespace ConsoleApp1.Entity
{
public class FruitDbContext : DbContext
{
public DbSet<Fruit> Fruits { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionBuilder)
{
optionBuilder.UseSqlServer(@"Data Source = xxx; Database=Fruitdb; Integrated Security = True; Connect Timeout = 15; Encrypt = False; TrustServerCertificate = True; ApplicationIntent = ReadWrite; MultiSubnetFailover = False");
}
}
}
我认为这与我的课无关,但无论如何我都列出来了。我试图将这些工具移动到其他文章中建议的json文件中的自己的部分,但我仍然得到相同的错误。
有什么想法?
答
如果你选择错误,它说的最后一行 - Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json
在你project.json
,您仅添加了依赖。您还需要添加工具部分。请参阅下样品 -
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.1",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"tools": {
....
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4" << Add respective version here
....
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
欲了解更多详情,请参阅升级工具包款here
我在JSON手动添加工具这个时候抱怨“没有可执行找到匹配的命令‘的dotnet-EF’我做不记得发布命令 – user1205746
@ user1205746 plz检查我的更新答案。另外,你可以参考升级工具包部分[这里](https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-entity -framework-core-1-1 /) – Sanket
已经尝试了你的建议并将软件包升级到了1.1,甚至安装了.NetCore 1.1 SDK。得到了一个不同的错误:术语'Add-Migration'不被认为是na我的一个cmdlet,函数,脚本文件或可操作的程序。 – user1205746