如何在部署时使用变量而不是XML转换来转换Web.Config? [英] How to transform Web.Config using variables instead of XML transform at deployment?

本文介绍了如何在部署时使用变量而不是XML转换来转换Web.Config?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前拥有以下 Web.Release.config 文件,该文件在部署时会转换 Web.config .

We currently have the following Web.Release.config file that transforms Web.config at deployment time.

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
  <elmah>
    <errorLog xdt:Transform="Remove" />
    <errorMail xdt:Transform="Remove" />
    <errorMail xdt:Transform="Insert" from="reports@companyxyz.com" to="a23cv@companyxyzteam.slack.com" subject="Dashboard Error" async="true" smtpPort="587" smtpServer="smtp.sendgrid.net" userName="apikey" password="password123" />
  </elmah>
</configuration>

如您所见,配置文件包含诸如 password 之类的敏感信息.

As you can see, the config file contains sensitive information like password.

管道工件包含脚本,内容,捆绑软件,并且与该问题最相关的是 Web.Debug.config Web.Release.config Web.config :

The pipeline artifact contains Scripts, Content, Bundles, and most relevant to this question the Web.Debug.config, Web.Release.config and Web.config:

发布工件后,发布管道将触发Azure App Service任务部署:

When the artifact is published, the release pipeline triggers the Azure App Service task deployment:

steps:
- task: AzureRmWebAppDeployment@4
  displayName: 'Deploy Azure App Service'
  inputs:
    azureSubscription: '$(Parameters.ConnectedServiceName)'
    appType: '$(Parameters.WebAppKind)'
    WebAppName: '$(Parameters.WebAppName)'
    enableCustomDeployment: true
    TakeAppOfflineFlag: false
    RenameFilesFlag: false
    enableXmlTransform: true

我们不希望XML转换是一种更改诸如 password 甚至 to 电子邮件属性的属性的方法,我们希望将其存储为变量,可能存储在释放管道(可能创建一个包含这些属性/值的 elmah 组),并使用该变量来转换 Web.config 文件.当然,我们仍然希望发生其他XML转换设置,例如< system.web> ,但是我们希望将< elmah> 中的属性转换为使用变量而不是XML文件进行转换.

Instead of the XML transformation being the one to change the attributes like password, or even to email attribute, we would like to store those as variables, possibly in the release pipeline (maybe create an elmah group containing these attributes/values) and use that such variables to transform the Web.config file. Of course, we still would want other XML transform settings to occur, such as the <system.web>, but we want attributes like those in <elmah> to be transformed using variables instead of the XML file.

我们如何做到这一点?我知道如何创建变量,但是我不确定如何或是否有可能使用变量而不是 Web.Debug.config 来转换 Web.config 文件.或 Web.Release.config

How can we accomplish this? I know how to create the variables, but I am not sure how or if its even possible to transform the Web.config file using variables instead of the Web.Debug.config or Web.Release.config

是否存在可以执行此操作的设置/任务?

Is there a setting/task that can do this?

推荐答案

我不确定使用变量而不是使用Web.Debug.config或Web.Release.config来转换Web.config文件的方式或方法是否可行

I am not sure how or if its even possible to transform the Web.config file using variables instead of the Web.Debug.config or Web.Release.config

我们可以安装扩展替换令牌,添加变量并设置变量以保密,然后添加任务替换令牌来替换 web.configure 变量并在Azure DevOps管道中使用它.

We could install the extension Replace Tokens, add variable and set the variable to secret then add the task Replace Tokens to replace the web.configure variable and use it in the Azure DevOps pipeline.

打开 .csproj 文件并添加字段< CopyToOutputDirectory>从不</CopyToOutputDirectory> ,它将不会复制 Web.Release.config 文件.

Open .csproj file and add the field <CopyToOutputDirectory>Never</CopyToOutputDirectory>, it will not copy the Web.Release.config file.

<None Include="Web.Release.config">
      <DependentUpon>Web.Release.config</DependentUpon>
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </None>

这篇关于如何在部署时使用变量而不是XML转换来转换Web.Config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆