【Azure DevOps系列】Azure DevOps構建.NET EFCore應用程序

本章我們將看到如何通過Azure DevOps使用EFCore CLI工具將我們的EFCore應用程序進行數據庫重建,當然這種操作我不建議使用,建議使用CLI生成sql腳本形式進行發佈並遷移。

  • 設置代理服務器sdk
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '3.x'
  • 安裝dotnet-ef

安裝Entity Framework Core CLI工具,用於後面對數據庫的操作

- task: CmdLine@2
  displayName: 'install dotnet-ef'
  inputs:
    script: 'dotnet tool install -g dotnet-ef'
  • 刪除數據庫

dotnet ef database drop --project <path to your csproj with drop> -f

選項 Short 說明
--force -f 不要確認。
--dry-run row 2 col 2 顯示要刪除的數據庫,但不刪除它。
- task: CmdLine@2
  displayName: 'drop database'
  inputs:
    script: |
      dotnet ef database drop --project host/EasyAbp.PrivateMessaging.Web.Unified/EasyAbp.PrivateMessaging.Web.Unified.csproj -f
  • 更新數據庫

將數據庫更新爲上一次遷移或指定的遷移。
dotnet ef database update --project <path to your csproj with update>

- task: CmdLine@2
  displayName: 'update database'
  inputs:
    script: | 
      dotnet ef database update --project host/EasyAbp.PrivateMessaging.Web.Unified/EasyAbp.PrivateMessaging.Web.Unified.csproj

通過如上過程我們便可以將數據庫在pipeline執行中更新到我們的數據庫中,但是如上這種操作我不建議在生產環境中進行使用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章