【发布时间】:2018-04-06 23:47:18
【问题描述】:
我在 .net core 2.0 中添加数据库迁移时遇到问题。 我收到以下错误:
An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: One or more errors occurred. (Webpack dev middleware failed because of an error while loading 'aspnet-webpack'. Error was: Error: Cannot find module 'aspnet-webpack'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Dries\AppData\Local\Temp\quzf2u2y.rt0:83:19)
at __webpack_require__ (C:\Users\Dries\AppData\Local\Temp\quzf2u2y.rt0:20:30)
at createWebpackDevServer (C:\Users\Dries\AppData\Local\Temp\quzf2u2y.rt0:62:26)
at C:\Users\Dries\AppData\Local\Temp\00o3h05d.izo:114:19
at IncomingMessage.<anonymous> (C:\Users\Dries\AppData\Local\Temp\00o3h05d.izo:133:38)
at emitNone (events.js:86:13)
Current directory is: D:\Projects\Jeroen Fiers\Projecten\Fiers\bin\MCD\Debug\netcoreapp2.0
)
Unable to create an object of type 'ApplicationDbContext'. Add an implementation of 'IDesignTimeDbContextFactory<ApplicationDbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.
我的 Program.cs 调整如下:
public class Program{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
奇怪的是迁移之前(曾经)工作过。
【问题讨论】:
-
检查你的启动项目和在 npm 控制台的下拉列表中选择的项目。对我来说,只有当两者都指向数据访问库(定义对象类)时它才有效
-
目前只有一个项目:/
标签: c# .net entity-framework asp.net-core asp.net-core-2.0