在GitHub工作流程中应用EF迁移

时间:2019-12-08 10:51:46

标签: asp.net-core github-actions ef-core-3.0

我有一个带EF Core 3.0的Asp Net Core项目的GitHub存储库。我添加了以下工作流,以在每次更新develop分支时运行

name: Develop Build
on:
  push:
    branches:
      - develop
  pull_request:
    branches:
      - develop
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.0.102-servicing-014397
    - name: Build with dotnet
      run: dotnet build --configuration Release
    - name: Test with dotnet
      run: dotnet test --configuration Release
    - name: Update database
      run: dotnet ef database update --c DataContext --p MyProj --s MyProjFactory

最后一行返回错误:

Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET Core program, but dotnet-ef does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
##[error]Process completed with exit code 1.

如何使用此工作流程将最新的迁移应用于目标数据库?

2 个答案:

答案 0 :(得分:1)

您可能想在Windows environment中运行工作流,即使用windows-latest而不是ubuntu-latest。您可以看到Windows here上安装的软件。

对于Windows Server 2019,它说:

  

PATH:包含dotnet.exe的位置

对于Linux环境,没有提到dotnet在PATH中

答案 1 :(得分:0)

我还必须添加命令来安装EF工具并还原所有工具,以使我的工作流程正确运行:

- name: Update database
  run: |
    dotnet tool install --global dotnet-ef
    dotnet tool restore
    dotnet ef database update --c DataContext --p MyProj --s MyProjFactory
  env:
    ASPNETCORE_ENVIRONMENT: Development