WebDeploy Publish Profiles (and their accompanying IT:AD:XDT transformation) can be used to deploy known/fixed settings based on Build Configuration (Debug, Release), such as Debug=true|false, or ConnectionString CatalogName="MyAppDevSS"|"MyApp".
But it's not appropriate for everything: * Security Leakage: using WCT to keep ST, QAT, and PROD environment settings in a file that is source controlled, available to all developers, is not secure. * It doesn't take into account target Environments – beyond Configuration – such as ST, UAT, PROD, or web farms, or Azure – where the same software is deployed to different servers requiring different slightly configurations.
Parameters are useful when:
Parameters are used to drive * the command line .cmd that Visual Studio the IIS import mechanism (which has the advantage of providing a means for the installer to override the values as needed).
When you Create a Publish Profile you are creating an IT:AD:MSBuild Project file, that by convention will be looking to see if you have created an accompanying Parameters.xml file.
By default, Visual Studio will have not made the Parameters.xml file for you – it's up to you to Add a New Item... → Xml File to the root of the Project:
BuildAction=None.MyApp.SetParameters.xmlparameter element, with a nested parameterEntry.parameter can have more than one parameterEntry to search for and replace in more than one location.parameterValidation element nested under a parametertag is more important than it looks…
For each transformation, you'll be defining a parameter element, with a nested parameterEntry:
<?xml version="1.0" encoding="utf-8" ?>
<parameters>
<parameter name="DataBaseUserName"
description="Database username"
defaultValue="MySQLDatabaseUser"
tags="MySQLParam"
<parameterEntry
kind="TextFilePosition"
scope="application\\settings.php"
match="92;21;11" />
</parameter>
</parameters>
The element names and attributes are:
parametername: required unique name to identify the parameter with e.g. “Service 1 endpoint address”description: this text shows up in the UI of IIS Manager to help the user fill in the value so anything clarifying the parameter is cool…defaultValue: optionally you can specify a default value for a parameter so that while installing the package a user may know what kind of values are permissible…tags: tags help the UI determine how to construct the UI for end installers to install the product. The following are the choices:iisapp: Identities the parameter as the application path (defaultValue should be set to Default Web Site/application1) to install the application.hidden: a Hidden parameter is not shown to the user as part of the installation UI (a defaultValue must be set though).SQL Indicates the parameter is related to a database.Password: The UI will hide the value of that password.New: When used together with the Password tag, this identifies a field that will be used to set a new password.dbUsernamedbUserPassworddbAdminUsernamedbAdminPassworddbServerdbName SQLConnectionString: identifies that a field (usually a Hidden one) is being used as a connection string to a database. Validate: only allowed when specified with one of the connection string tags. Validate will validate the database credentials before allowing the user to proceed through the rest of the installation.
* parameterEntry:
kind: there are several kinds of parameters but the key ones to remember are:XmlFile – Use this for web.config, any settings XML files etc where you can make replacements using XPathTextFile – Use this for non-XML file where you can make replacements by looking for fixed text or token within a file. e.g. you can put @@replaceme@@ in the a settings.ini file and during installation that text can be replacedmatch - This depends upon the parameter kind… For e.g. for XmlFile parameter the match expression would be a XPath… For TextFile the match expression could be @@replaceme@@ which you might pre-place in the file…scope: Regular Expression to determine what entities (files e.g. web.config, DBs, Web Deploy providers etc) does the parameter apply to.parameterValidation:
* type=“AllowEmpty”:
* <parameterValidation type="Boolean" />
* <parameterValidation type="Enumeration" validationString="value1,value2,value3,value4" />
* <parameterValidation type="RegularExpression" validationString=".+" />
* <parameterValidation type="RegularExpression,allowEmpty" validationString="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$" />
### Troubleshooting ###
* Parameters only transform – they are not as powerful as WCT and won't inject in settings that are not currently in the web.config or target files.
* The same goes for the Creating of the Root VirtualDirectory Path parameter as well: the deployment package has to be including IIS settings for it to have something to replace.
## Resources ##
* http://vishaljoshi.blogspot.co.nz/2010/07/web-deploy-parameterization-in-action.html
* http://www.iis.net/learn/develop/windows-web-application-gallery/reference-for-the-web-application-package
* http://vishaljoshi.blogspot.co.nz/2010/07/web-deploy-parameterization-in-action.html