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

Apply EF migrations in GitHub workflow

我的 Asp Net Core 项目和 EF Core 3.0 有一个 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

最后一行returns有错误:

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.

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

您可能希望 运行 您的工作流程 windows environment, i.e. using windows-latest rather than ubuntu-latest. You can see the software installed on windows here

对于Windows Server 2019,它表示:

PATH: contains location of dotnet.exe

没有提到 dotnet 在 Linux 环境的 PATH 上

我还必须添加命令来安装 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