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

标签 c# azure msbuild web-config msbuild-wpp

我创建了一个 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/

相关文章:

c# - 在不重启服务器的情况下查看代码更改

c# - 如何高效地进行单元测试

c# - 如何以编程方式判断我是否在 Medium Trust 下运行?

msbuild - 使用 MSBuild 通过 TeamCity 运行 XUnit 测试

MSBuild 和创建 ZIP 文件

c# - System.Text.RegularExpressions.Regex.Matches 的性能特征 - 一个错误?

azure - Microsoft Azure 入门 - 本地副本?

indexing - 如何在azure云应用程序中维护lucene索引

azure - 用于 asp.net core 的 ELMAH

c# - 具有持续集成的多语言应用程序工具包