1

我已經在VS2017(.net core 2.0)中開始了一個新的React + Redux項目。默認模板沒有使用數據庫,所以我只是手動添加了實體框架的使用。它編譯良好,但是當我嘗試使用命令VS2017 + ReactJS +使用實體框架拋出和移植錯誤

dotnet ef migrations add "Initial" 

,我發現了一個錯誤添加遷移:

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\sibvic\AppData\Local\Temp\iu25u5dg.r0n:83:19) 
at __webpack_require__ (C:\Users\sibvic\AppData\Local\Temp\iu25u5dg.r0n:20:30) 
at createWebpackDevServer (C:\Users\sibvic\AppData\Local\Temp\iu25u5dg.r0n:62:26) 
at C:\Users\sibvic\AppData\Local\Temp\ftqvg4wq.l1l:114:19 
at IncomingMessage.<anonymous> (C:\Users\sibvic\AppData\Local\Temp\ftqvg4wq.l1l:133:38) 
at emitNone (events.js:86:13) 
Current directory is: C:\projects\test\bin\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. 

看起來這個功能太新。沒有太多的信息,我可以找到。並且不能自己弄清楚什麼是錯誤的(至少,橡皮鴨方法也行不通)。

任何想法如何解決它?

回答

1

在從dotnet core 1.1遷移到2.0時,我遇到了同樣的問題。

我不得不更新我的執行計劃類的到以下幾點:

public class Program 
{ 
    public static void Main(string[] args) 
    { 
     BuildWebHost(args).Run(); 
    } 

    public static IWebHost BuildWebHost(string[] args) => 
     WebHost.CreateDefaultBuilder(args) 
      .UseStartup<Startup>() 
      .Build(); 
} 

我知道這是不是陣營+終極版,但也許它可以幫助你。

+0

這絕對幫了我。以下是官方文檔的鏈接:https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/index#update-main-method-in-programcs – bvpb