entity-framework - 使用 Azure Pipeline 任务进行 EF 迁移

标签 entity-framework powershell .net-core azure-devops azure-pipelines

在我看来,使用带有任务的 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/

相关文章:

c# - 无法在 .NET Core 中加载文件或程序集 'System.Runtime, Version=4.1.0.0'

c# - 将委托(delegate)传递给 EF Core 中的 linq 查询

entity-framework - 你能举一个实体 SQL 有意义的例子吗?

powershell - 使用Write-Host时删除对象之间的空间

powershell - 目的地的复制项目问题

c# - 如何将程序集信息添加到由 dot net core 2.0 生成的 PrecompiledViews dll

c# - 如何更改过滤器和外键列在 DynamicData 站点中的呈现方式?

c# - DbContext缓存

azure - 通过Azure数据工厂创建blob存储容器

c# - dotnet core IdentityModel 不会自省(introspection) token