azure-devops - 为每个发布环境为 Azure 网站部署转换 web.config

标签 azure-devops azure-deployment

在 Visual Studio Team Services(以前是 Visual Studio Online)中,我有三个发布环境,每个环境都有一个 Azure 网站部署步骤。

我可以通过指定选择 Web.Uat.config 的“BuildConfiguration”变量(例如 Uat)来转换构建步骤的 web.config。

但是,我有多个使用此构建配置的发布环境,它们都需要转换 Web 配置(例如 Dev、Test、Uat、Live)。

是否可以在 Azure 网站部署步骤之前指定用于每个发布环境的 Web 配置转换?

注意:我意识到可以在 Azure 门户网站的“所有设置”下指定简单的应用设置和连接字符串,但我需要做的不仅仅是转换这些简单的设置,并且已经为我的解决方案中的每个环境配置了 web 配置转换

最佳答案

作为 Release Management Utility Tasks 一部分的分词器任务允许根据环境转换配置文件。

可以使用包含所有环境的所有配置的单个 JSON 配置文件,任务将根据环境自动选择正确的配置。

{
  "<environment>": {
    "CustomVariables": {
    "Variable1": "value1",
    "Variable2": "value2",
  },
    "ConfigChanges": [
        {
          "KeyName": "/configuration/appSettings/add[@key='ServiceURL']",
          "Attribute":"value",
          "Value":"https://ServiceURL"
        },
        {
          "KeyName": "/configuration/appSettings/add[@key='EnableDebugging']",
          "Attribute":"value",
          "Value":"false"
        },
        {
          "KeyName":“/configuration/connectionStrings/add[@name='databaseentities']”,
          "Attribute": "connectionString",
          "value": "Integrated Security=True;Persist Security Info=False;Initial Catalog=DB;Data Source=servername"
        }
    ]
}

像这样,您可以在单个 JSON 文件中拥有多个环境及其配置,并且标记生成器任务将根据部署进行的环境修改您的配置。

阅读上述链接的详细信息以了解更多信息。

关于azure-devops - 为每个发布环境为 Azure 网站部署转换 web.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37260243/

相关文章:

node.js - 在 Azure 应用服务中部署前端和后端应用程序的最佳方法是什么?

Powershell 脚本完成但退出并显示错误代码 1

azure-devops - Azure Devops 插入新阶段或重新排序管道

Azure Key Vault - 添加部署槽的访问策略

Azure PowerShell : Enable Application Diagnostics and Site Diagnostics

更新 VS Code 后,Azure Web 应用服务部署失败,显示 "SyntaxError: Unexpected token"

azure - 如何将自定义域名与Azure ARM模板部署绑定(bind)

azure-devops - 将 sonarqube 分析与 Ci 构建集成的问题

sql-server - 使用 Azure DevOps 连接到专用链接上的 Azure SQL

azure - 在 VSTS 中添加 Azure 订阅作为任务组的参数