gpt4 book ai didi

c# - 如何使用 Targets.wpp 更改 Web.Config 的应用程序设置

转载 作者:太空宇宙 更新时间:2023-11-03 10:29:49 24 4
gpt4 key购买 nike

我创建了一个 wpp.targets 文件,它在 azure 中完成所有部署。我想在部署到azure期间更改webconfig的appsetting属性。我在http://sedodream.com/PermaLink,guid,25ddd39e-59de-4e35-becc-de19dcc5e4ea.aspx中找到了一个样本,它使用 pubxml 和parameters.xml。我想使用 wpp.targets 而不是 pubxml。

  <appSettings>
<!-- TODO: set this in the azure config -->
<add key="customer" value="xyz" />
</appSettings>

需要在部署期间将客户值更新为“client”,并且 web.config 文件应反射(reflect)已部署文件夹中的更改,如下所示

  <appSettings>
<add key="customer" value="client" />
</appSettings>

回答

我已经在 msDeploy 中使用了 ProjectParametersXMLFile

msbuild Api.csproj    /p:ProjectParametersXMLFile="c:\parameter.xml"/p:PublishSettingsFile=%publishFileLocation% 

最佳答案

您可以使用参数xml文件

例如

<parameters >
<parameter name="customer" description="web Job queue name" defaultValue="sitetest1">
<parameterEntry kind="XmlFile"
scope="\\web.config$"
match="/configuration/appSettings/add[@key='customer']/@value" />
</parameter>
<parameter name="customer" description="web Job queue name" defaultValue="sitetest">
<parameterEntry kind="XmlFile"
scope="\\app.config$"
match="/configuration/appSettings/add[@key='customer']/@value" />
</parameter>
</parameters>

当您在 Azure 中部署时,此文件将根据您提供的默认值更改应用程序设置

关于c# - 如何使用 Targets.wpp 更改 Web.Config 的应用程序设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30601109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com