NOTE: This is a cross-post from bilalaslam.com
When should you use Replace Rules vs. Parameters with Web Deploy? Read on, brave reader!
Web Deploy supports several ways to transform objects during deployment. Why would you want to do this? Because, as I have noted in earlier blog posts, connection strings and even site bindings differ from environment to environment.
The first way is to parameterize. I have covered parameterization in a previous blog post, but I’ll give a quick recap here. A parameter defines a part of an object that should be changed every time the deployment happens. For example, you may want to build a deployment package and parameterize a database connection string. The person who does the deployment is responsible for providing a value for this parameter each time the deployment happens. Here’s how you declare the parameter:
msdeploy.exe -verb:sync -source:apphostconfig -dest:package=c:\temp\package.zip -declareParam:name ="Handler Mappings Access Type",scope="apphostconfig",match="//handlers[@accessType]",kind="ProviderPath"
If you look at the ZIP of the package, it now contains a file called parameters.xml with the following contents:
<parameters> <parameter name="Handler Mappings Feature Permissions"> <parameterEntry kind="DeploymentObjectAttribute" scope="appHostConfig" match="//handlers/@accessPolicy" /> </parameter> </parameters>
When installing the package, you can specify a value for the parameter like this:
msdeploy.exe -verb:sync -source:package=c:\temp\package.zip -dest:auto -setParam:name="Handler Map pings Feature Permissions",value="Read,Script"
The second way is to use a replace rule. A replace rule literally replaces an object or a piece of an object at the time of deployment. You should use replace rules when you know the new value. This blog post covers replace rules. Here’s a sample replace rule which changes an attribute in a node in applicationHost.config from “Read” to “Read,Script” (this sets a Handler Mappings feature setting):
msdeploy.exe -verb:sync -source:apphostconfig -dest:package=c:\temp\package.zip -replace:objectName=handlers,scopeAttributeName=accessPolicy,match="Read",replace="Read,Script "