在appSettings外部更新web.config中的变量

编程入门 行业动态 更新时间:2024-10-26 10:32:16
本文介绍了在appSettings外部更新web.config中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要在Azure TFS中更新web.config中的值.我能够获取被替换为appSettings的一部分的connectionString的值(为了起作用,我需要启用名为XML变量替换的设置(在IIS Web Deploy下).

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.

当前,我正在使用替换令牌"任务(位于 github/qetza/vsts-replacetokens-task#readme )

Currently I am using the Replace tokens task (available at github/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仅空行. 主题需要用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,如下所示: "> docs.microsoft/zh-cn/aspnet/web-forms/overview/deployment/web-deployment-in-the-enterprise/configuring-parameters-for-web-打包部署

Add a parameters.xml to your project, as described here: docs.microsoft/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部署任务中使用其他参数传递值 -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中的变量

本文发布于:2023-11-09 06:17:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571605.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   appSettings   web   config

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!