sayedihashimi / slow-cheetah

XML Transforms for app.config and other XML files
Other
242 stars 51 forks source link

Can I replace part of a value? #200

Open MrYossu opened 7 years ago

MrYossu commented 7 years ago

All of the examples I've seen of using SlowCheetah involve replacing the full contents of an attribute in a node.

What I want to do is replace part of an attribute value. For example, if my App.config file contains the following...

  <endpoint address="http://localhost:24953/Services/AuditService.svc"
            binding="customBinding"
            bindingConfiguration="CustomBindingDefault"
            contract="AuditServiceReference.AuditService"
            name="AuditService" />

...then I can add a transform to my App.Release.config file as follows...

  <endpoint address="http://www.mydomain.co.uk/Services/AuditService.svc"
            behaviorConfiguration="LargeMessageBehavior"
            binding="customBinding"
            bindingConfiguration="CustomBindingDefault"
            contract="AuditServiceReference.AuditService"
            name="AuditService"
            xdt:Transform="Replace"
            xdt:Locator="Match(name)" />

...and it will produce the correct output.

However, as I have a lot of these service references, I have lots of entries like the above in the App.config file, with corresponding entries in the App.Release.config file.

What I would really like to do is only have to add one entry to the App.Release.config file that works all of the service entries in the App.config file, ie it transforms localhost:24953 into www.mydomain.co.uk for each node in the file.

Is this possible, or do I have to have a separate entry in my App.Release.config file for every service?

MrYossu commented 7 years ago

Anyone?

todthomson commented 7 years ago

65197903

jviau commented 7 years ago

SlowCheetah uses Microsoft.Web.Xdt to process the XML transforms. Here is the MSDN page for it. I believe the SetAttributes section is what you are looking for.

sayedihashimi commented 7 years ago

Replacing a portion of the value is not supported with XDT out of the box. It is possible to create a custom XDT transform which can replace a portion of an attribute value. I describe how to do this in an old blog post at http://sedodream.com/2010/09/09/extendingxmlwebconfigconfigtransformation.aspx.

With that said, I've never tested using a custom transform with SlowCheetah. Also @jviau and others are in the middle of refactoring the code, so if you get it working now you may need to update a reference later.