4

Is there any way to transform web.config custom sections values when using MSDeploy ?

  <configSections>
    <sectionGroup name="myGroup">
      <section name="data" type="MyApp.DataConfigurationSection, MyApp.Data" />
    </sectionGroup>
  </configSections>

  <myGroup>
    <data interval="3" useCache="true" />
  </myGroup>

According to build configuration i need for exemple to change "useCache" value.

2 Answers 2

4

Write transformation in config transformation file (web.config.release)

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <myGroup>
    <data useCache="false" xdt:Transform="SetAttributes(useCache)" />
  </myGroup>
</configuration>
Sign up to request clarification or add additional context in comments.

Comments

1

Yes, MSDeploy supports this quite easily.

When you create a deployment package you want to use the -declareParm option to create a replaceable parameter in your deployment package. You'd use something like:

-declareParam:name=UseCache,kind=XmlFile,scope=web.config,match="/configuration/myGroup/data/@useCache"

Then when deploying your package, you'd use the -setParm command to replace the parameter during deployment. Something like:

-setParam:name=UseCache,value="false"

This example would replace the UseCache parameter, which points to the useCache attribute in the web.config file with "false".

You can declare any number of parameters to be replaced and MSDeploy supports using files to hold the parameters. Files are simple Xml files you would then use the -setParamFile:<filename> and -declareParamFile:<filename> syntax.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.