New release of my Generate Parameters.xml tools to add support for app.config files
I recently released an updated version of my Generate Parameters.XML tool for Visual Studio. This release adds support for generating parameters.xml files from app.config files as well as web.config files Why you might ask why add support for app.config files when the parameters.xml model is only part of WebDeploy? Well, at Black Marble we like the model of updating a single file using a tokenised set of parameters from within our DevOps CI/CD pipelines. It makes it easy to take release variables and write them, at deploy time, into a parameters.xml file to be injected into a machine’s configuration. We wanted to extend this to configuring services and the like where for example a DLL based service is configured with a mycode.dll.config file The injection process of the parameters.xml into a web.config file is automatically done as part of the WebDeploy process (or a VSTS extension wrapping WebDeploy), but if you want to use a similar model for app.config files then you need some PowerShell. For example, if we have the app.config
1<?xml version="1.0" encoding="utf-8" ?>
2<configuration>
3 <applicationSettings>
4 <Service.Properties.Settings>
5 <setting name="Directory1" serializeAs="String">
6 <value>C:ABC1111</value>
7 </setting>
8 <setting name="Directory2" serializeAs="String">
9 <value>C:abc2222</value>
10 </setting>
11 </Service.Properties.Settings>
12 </applicationSettings>
13 <appSettings>
14 <add key="AppSetting1" value="123" />
15 <add key="AppSetting2" value="456" />
16 </appSettings>
17 <startup>
18 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
19 </startup>
20</configuration>
My extension generates a tokenised parameters.xml file
1<parameters>
2 <parameter name="AppSetting1" description="Description for AppSetting1" defaultvalue="\_\_APPSETTING1\_\_" tags="">
3 <parameterentry kind="XmlFile" scope="\\App.config$" match="/configuration/appSettings/add\[@key='AppSetting1'\]/@value" />
4 </parameter>
5 <parameter name="AppSetting2" description="Description for AppSetting2" defaultvalue="\_\_APPSETTING2\_\_" tags="">
6 <parameterentry kind="XmlFile" scope="\\App.config$" match="/configuration/appSettings/add\[@key='AppSetting2'\]/@value" />
7 </parameter>
8 <parameter name="Directory1" description="Description for Directory1" defaultvalue="\_\_DIRECTORY1\_\_" tags="">
9 <parameterentry kind="XmlFile" scope="\\App.config$" match="/configuration/applicationSettings/Service.Properties.Settings/setting\[@name='Directory1'\]/value/text()" />
10 </parameter>
11 <parameter name="Directory2" description="Description for Directory2" defaultvalue="\_\_DIRECTORY2\_\_" tags="">
12 <parameterentry kind="XmlFile" scope="\\App.config$" match="/configuration/applicationSettings/Service.Properties.Settings/setting\[@name='Directory2'\]/value/text()" />
13 </parameter>
14 </parameters>
The values in this parameters.xml file can be updated using a CI/CD replace tokens task, we use Colin's ALM Corner Build & Release Tools, Replace Tokens, in exactly the same way as we would for a web.config Finally the following PowerShell can be used to update the app.config from this parameters.xml
Thus giving a consistent way of updating configuration files for both web.config and app.config files