在 appSettings 之外更新 web.config 中的变量 [英] Updating variables in web.config outside appSettings

查看:25
本文介绍了在 appSettings 之外更新 web.config 中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新 Azure TFS 中 web.config 中的值.我能够将 connectionString 的值替换为 appSettings 的一部分(为此,我需要启用名为 XML 变量替换的设置(在 IIS Web 部署下).

I need to update values in web.config in Azure TFS. I am able to get the value for connectionString replaced which is part of the appSettings (for this to work, I needed to enable the setting named XML variable substitution (under IIS Web Deploy).

但是,web.config 中还有其他区域不会被替换.

However, there are other areas within web.config which do not get replaced.

我尝试了几种不同的方法,使用不同的任务进行令牌替换,使用变量的发布"或环境"设置,使用变量组.然而,这些都没有奏效.

I have tried several different approaches, using different tasks for token replacement, using the "Release" or "Environment" setting for variables, using variable groups. However, none of these worked.

目前我正在使用替换令牌任务(可在 https://github.com/qetza/vsts-replacetokens-task#readme )

Currently I am using the Replace tokens task (available at https://github.com/qetza/vsts-replacetokens-task#readme )

我已将令牌前缀和后缀设置为 __(以匹配 web.config)

I have set the Token Prefix and Suffix to __ (to match with what is web.config)

这是 web.config 文件的摘录

Here is an extract of the web.config file

<?xml version="1.0"?>
<configuration>
    <appSettings>
        <add key="ConnectionString" value="__ConnectionString__"/>
    </appSettings>
    <system.web>
        <pages theme="__Theme__" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
            <controls>
                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            </controls>
        </pages>
    </system.web>
    <system.serviceModel>       
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
        <bindings>
            <customBinding>
                <binding name="TestBinding1">
                    <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    </textMessageEncoding>
                    <httpsTransport manualAddressing="false" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" requireClientCertificate="false" />
                </binding>
            </customBinding>
            __basicHttpBindingOptionalBinding__
        </bindings>
        <client>
            <endpoint address="__TestEndPoint__" binding="customBinding" bindingConfiguration="TestBinding1" contract="BSEInspectionsWebServiceForFDA.StateDataTransfer" name="StateDataTransferPort" />
            __endpointOptionalEndpoint__
        </client>
    </system.serviceModel>
</configuration>

我希望basicHttpBindingOptionalBinding 和endpointOptionalEndpoint 只有空行.Theme 需要替换为 TestTheme,TestEndPoint 需要设置为变量中定义的值.

I expect only blank lines for basicHttpBindingOptionalBinding and endpointOptionalEndpoint. The Theme needs to be replaced with TestTheme and TestEndPoint needs to be set with the value defined in variables.

推荐答案

将 parameters.xml 添加到您的项目中,如下所述:https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/web-deployment-in-the-enterprise/configuring-parameters-for-web-包部署

Add a parameters.xml to your project, as described here: https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/web-deployment-in-the-enterprise/configuring-parameters-for-web-package-deployment

在那里指定参数,例如myEndpointAddress".

specify parameter there, for example, "myEndpointAddress".

然后在 IIS Web Deploy Task 中使用附加参数来传递值-setParam:name='myEndPointAddress',value='new_value'

Then in IIS Web Deploy Task use additional arguments to pass the value -setParam:name='myEndPointAddress',value='new_value'

这篇关于在 appSettings 之外更新 web.config 中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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