【问题标题】:Entity Framework Core Migration in Azure PipelineAzure Pipeline 中的实体框架核心迁移
【发布时间】:2022-01-28 02:58:56
【问题描述】:

有谁知道为什么在从 YAML 运行 ef 迁移而不是开发人员命令提示符时需要连接字符串?

我认为这可能与未从管道变量中提取 connectionString 值有关。

我在这里设置连接字符串:

builder.Service.AddDbContext<myContext>(options=>
  options.UseSqlServer(builder.Configuration.GetConnectionString("MyDB")));

我已尝试将管道变量的名称命名为

MyDB
ConnectionStrings_MyDB
ConnectionStrings:MyDB

以下 YAML 给我错误“值不能为空。(参数'connectionString')”

- task: DotNetCoreCLI@2
  displayName: Create SQL Scripts
  inputs:
    command: custom
    custom: 'ef '
    arguments: migrations script --output $(sqlOutputPath) --idempotent --project $(solution)

但是,从开发人员命令提示符运行以下命令会成功执行:

dotnet ef migrations script --output complete.sql --idempotent --project myproject

【问题讨论】:

  • 您是否定义了变量sqlOutputPathsolution?如果是,您确定solution 的值正确吗?
  • 是的,如果找不到项目,它会抛出一个项目未找到异常。
  • 好吧,我问是因为您的变量建议您使用解决方案名称。你确定solution是项目名吗?
  • 我很肯定,因为项目构建成功。此参数可用于解决方案和项目。

标签: entity-framework entity-framework-core yaml azure-pipelines


【解决方案1】:

原来我忘记将 Azure KeyVault 的引用添加到我的项目中;因此,它甚至没有查看 ConnectionString 的 keyvault。名称也需要是 ConnectionStrings--MyDB

【讨论】:

    猜你喜欢
    • 2020-06-21
    • 2021-06-27
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 2019-11-08
    • 2019-02-25
    相关资源
    最近更新 更多