Blazor The specified deps.json \bin\Debug\net5.0\BlazorWebApp.deps.json] does not exist

1.问题描述

问题描述:
使用Blazor添加迁移时出现如下错误:
The specified deps.json [C:\Project\Practice\202004\BlazorWebApp\BlazorWebApp\bin\Debug\net5.0\BlazorWebApp.deps.json] does not exist
在这里插入图片描述

2.解决问题思路

1、试试用dotnet ef CLI 进行迁移操作(官方文档)。
(1)相关命令如下所示:

//全局安装工具
dotnet tool install --global dotnet-ef

//更新工具
dotnet tool update --global dotnet-ef

//项目中需安装
dotnet add package Microsoft.EntityFrameworkCore.Design
//添加新迁移
dotnet ef migrations add "迁移名"

//更新数据库
dotnet ef database update 

(2)添加新迁移时,出现了如下错误,原因是在startup.cs中我未进行ef的相关配置。
在这里插入图片描述
(3)在startup.cs"中否配置EF,在appsetting.json中数据库连接字符串
在这里插入图片描述
在这里插入图片描述
相关配置如下:

 services.AddDbContext<MyDbContext>(opt => 
                opt.UseSqlServer(Configuration.GetConnectionString("MyDbContext"))
            );
 "ConnectionStrings": {
    "MyDbContext": "Server=.;Database=CovidAPI;User ID=sa;Password=3344520;Trusted_Connection=False"
  }

2、此时再次在"程序包管理器控制台"中添加迁移,依旧是出现如下错误:
在这里插入图片描述
3、尝试在cmd中使用dotnet ef添加迁移,此时使用可以dotnet ef migrations add initial命令可迁移成功

C:\Project\Practice\202004\BlazorWebApp\WebApp.Server>dotnet ef migrations add initial
Build started...
Build succeeded.
Done. To undo this action, use 'ef migrations remove'

4、使用dotnet ef database update命令可成功更新数据库

C:\Project\Practice\202004\BlazorWebApp\WebApp.Server>dotnet ef database update
Build started...
Build succeeded.
Done.

5、此时可看到数据库创建成功
在这里插入图片描述
注:使用程序包管理控制台失败的原因还未找到,后续找到了会在文章中更新

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值