Search code examples
c#azuremsbuildweb-configmsbuild-wpp

How to change app settings of Web.Config using targets.wpp


I have created a wpp.targets file which does all the deployment in azure. I want to change the appsetting property of webconfig during deployment to azure. I found a sample in http://sedodream.com/PermaLink,guid,25ddd39e-59de-4e35-becc-de19dcc5e4ea.aspx , which uses the pubxml and parameters.xml. I want to use wpp.targets instead of pubxml.

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

Need to update the customer value to "client" during deployment and web.config file should reflect the changes in the deployed folder like below

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

ANSWER

I have achieved using the ProjectParametersXMLFile in msDeploy

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

Solution

  • You can use parameter xml file

    for example

    <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>
    

    this file will change the appsettings when you deploy in azure based on default value you provide