2016-11-24 66 views
1

我創建了一個獨立的應用程序與dotnet在自包含的應用程序運行遷移

dotnet publish -c release 

部署包中包含.NET的核心運行時本身 - 所以,如果有人想使用的應用程序 - 不需要分別安裝.net核心運行時。

但我的問題是......是否有可能將dotnet.exe附加到部署包?

F.e. - 我的web應用程序expectes遷移的數據庫:

dotnet ef database update 

此命令不能從獨立的應用程序運行(無直達dotnet.exe)。

這種情況下的情景是什麼?我應該如何處理它?

+0

看看這個SO帖子:http://stackoverflow.com/questions/35324156/automatically-execute-migrations-when-publishing-asp-net-core-app – Klinger

+3

只要調用'context.Database.MigrateAsync( )'在代碼啓動過程中 – Tseng

回答

0

的解決方案是增加它在你的Startup.cs像

public void Configure(
    IApplicationBuilder app, 
    // ... various other parameters that you may have and below add the context that you want to run Migrations 
    YourDbContext db1) 
{ 
{ 
    // run the migrations before other code 
    db1.Database.Migrate(); 
    // ... 
} 

PS。這有點奇怪,但你把它作爲一個額外的參數添加到配置方法簽名,它工作(我想它自動實例化的dbContext對象,並調用該方法)。它爲我工作。