-
Notifications
You must be signed in to change notification settings - Fork 3
Home
When you using MSdeploy you should create a parameters.xml file that exposes your web.config settings at the time of installation. This enables good deployment habits, making it easier to set system specific values using deployment tools. The problem is that this file is a pain to write, it is series of XML blocks that contain XPath to find the entries to replace, typo’s are easy to introduce.
The best way to install this add-in via the Visual Studio Marketplace.
Once you have installed install this VSIX package, if you right click on a web.config file in the web project you will see an option to generate a parameters.xml file, if you click it, and if the parameters.xml file does not exist, it will be generated and added to the project.
Entries will be made for all appSettings and any custom applicationSettings blocks replacing the values with TAGS to be set via Release Management or your tool of choice.
So the web.config file
<configuration>
<applicationSettings>
<Service.Properties.Settings>
<setting name="Directory1" serializeAs="String">
<value>C:\ABC1111</value>
</setting>
<setting name="Directory2" serializeAs="String">
<value>C:\abc2222</value>
</setting>
</Service.Properties.Settings>
</applicationSettings>
<appSettings>
<add key="APPSETTING1" value="123" />
<add key="AppSetting2" value="456" />
</appSettings>
</configuration>
generates the parameters.xml
<parameters>
<parameter name="APPSETTING1" description="Description for APPSETTING1" defaultvalue="__APPSETTING1__" tags="">
<parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='APPSETTING1']/@value" />
</parameter>
<parameter name="AppSetting2" description="Description for AppSetting2" defaultvalue="__APPSETTING2__" tags="">
<parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='AppSetting2']/@value" />
</parameter>
<parameter name="Directory1" description="Description for Directory1" defaultvalue="__DIRECTORY1__" tags="">
<parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/Service.Properties.Settings/setting[@name='Directory1']/value/text()" />
</parameter>
<parameter name="Directory2" description="Description for Directory2" defaultvalue="__DIRECTORY2__" tags="">
<parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/Service.Properties.Settings/setting[@name='Directory2']/value/text()" />
</parameter>
</parameters>
If a parameters.xml file already exists then you are prompted first if you wish to replace it, if you don’t then you are prompted if you wish to add any new entries in the web.config, or do nothing.
All the work is done via an XSL Transform, so if you need to transform extra settings just download the source and add to the embedded XSLT resource then rebuild your forked version of the the VSIX package.
With Version 1.4.x two option settings were added. These can be access via Visual Studio IDE menu Tools > Options > Parameters XML Addin.
Two options are available
- Make Tokens Uppercase - if true (the default) all tokens are in the form TOKEN, if false tokens reflect the case of the web.config entries
- Generate Descriptions - if true (the default) a description added for each entry, if false the description is left blank
- Delimiter - defaults to __, can be changed so that the inserted values to replace use a different delimiter to avoid clashes with other text replacement systems. It is recommended that if this is changed any previously generated parameters.xml are fully regenerated.
So the tool won’t do everything, but should get you close to the file you need.
With Version 1.7 the add-in has been modified so that the parameters.xml can also be generated from an app.config file, as well as a web.config. This is to support a use case on a project I am involved in where PowerShell will be used to transform configuration files based on the parameters.xml - more details and worked example will follow.
If the parameters.xml file is generated from an app.config, then the scope in the parameters.xml entries will be
scope="\app.config$"
as opposed to
scope="\web.config$"