【问题标题】:JSON variable substitution in appsettings.json file is not working in Azure DevOps Releasesappsettings.json 文件中的 JSON 变量替换在 Azure DevOps 版本中不起作用
【发布时间】:2020-06-25 03:06:24
【问题描述】:

我正在使用 Visual Studio 2019 使用 ASP.NET Core 3.1 在 C# 中创建一个 Restful Web API。我正在尝试将发布管道中的 appsettings.json 文件中的值(AppSettings.ReleasePipeline)替换为每个阶段的不同值,但它没有在任何阶段设置,只是使用 appsettings.json 文件中的值已经存在了。

这是我的 appsetttings.json 文件:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "CodeCampDatabaseConnectionString": "Data Source=.;Initial Catalog=PSCodeCamp;User Id=sa;Password=Dallas!@#;Connect Timeout=30;"
  },
  "AppSettings": {
    "ReleasePipeline" : "Environment from AppSettings"
  }
}

我的发布管道中的变量如下所示:

如果有人能提供帮助,我将不胜感激。

【问题讨论】:

    标签: .net json azure devops


    【解决方案1】:

    此功能替换 JSON 配置文件中的值。它使用与发布管道和阶段变量的名称匹配的值覆盖指定 JSON 配置文件(例如,appsettings.json)中的值。

    要替换特定 JSON 文件中的变量,请提供以换行符分隔的 JSON 文件列表。文件名必须相对于根文件夹指定。

    如果要替换appsettings.json中的值,输入根文件夹的相对路径;例如content/website/appsettings.json。或者,使用通配符模式搜索特定的 JSON 文件。

    更多详情可以参考这个article。

    【讨论】:

    • 是的,就是这样。它现在正在工作!非常感谢您的快速回复!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 2020-05-16
    • 1970-01-01
    相关资源
    最近更新 更多