在我看来,使用带有任务的 yaml 构建管道运行迁移并不是一件容易的事,因为当我尝试创建运行 dotnet ef
的任务时出现以下错误。迁移。
==============================================================================
Task : PowerShell
Description : Run a PowerShell script on Linux, macOS, or Windows
Version : 2.151.1
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
==============================================================================
Generating script.
========================== Starting Command Output ===========================
##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\agent\_work\_temp\a2cda363-57d3-416e-80ae-fb82a650ff74.ps1'"
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]PowerShell exited with code '1'.
##[section]Finishing: Roll back migrations
在构建服务器上,我全局安装了 dotnet-ef。所以我现在不确定为什么它会给我这个错误。下面是 yml 脚本。
- task: PowerShell@2
displayName: "Apply migrations"
inputs:
targetType: 'inline'
script: |
dotnet ef database update --project $(Build.SourcesDirectory)\DataLayer\DataLayer
最佳答案
原来是windows用户问题。 dotnet core 3 不再将 dotnet-ef 内置到 dotnet 中,我知道这一点并将 dotnet-ef 安装为全局,但显然这样做是特定于机器上的用户的。创建构建管道的开发人员需要在同一台机器上为其用户全局添加 dotnet-ef 才能使其正常工作。希望这有助于协作环境中的其他人。
关于entity-framework - 使用 Azure Pipeline 任务进行 EF 迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59761685/