I need to switch out an IP address in multiple WCF services in web.config. With web.config transformation, is there any way, besides specifying each an every address by xpath, to create a search and replace statement. E.g. switch out IP address 1.2.3.4 with 4.3.2.1 for all instances of 1.2.3.4
Share
Say your Web.config is something like this (a simplified scenario, but // in XPath works everywhere):
then you will need something like this:
NOTE: this XPath will look for every element in the whole Web.config and check whether given element has address attribute with value equal to “1.2.3.4”.
If you need something more general then try this:
This will look at every XML element (due to the asterisk: *) and check whether it has address attribute with value equal to “1.2.3.4”.
So this will work for a file like this:
Now if you want to limit substitutions to a certain section i.e.
<system.serviceModel>then you can use an XPath like this:This will update addresses only in
<system.serviceModel>sectionGive those a try and choose the one that suits your needs most.
NOTE: This has a limitation that you need to specify what is the name of the attribute that contains the IP (1.2.3.4) but I think its better to be explicit rather than have magic happen here. If you have many attibute names just repeat the