Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XDT Config Transforms - ReplaceAll?

I've got a custom section in my web.config file similar to this structure:

<Messages>
  <Message id="1'>
     <Property Name="foo" value="bar" />
  </Message>
  <Message id="2'>
     <Property Name="foo" value="bar2" />
  </Message>
</Messages>

I want to apply a custom transformation on this such that I can change the value of ALL instances of the Property element with Name="foo" - but I cant seem to get it to work.

I've tried:

<Messages>
  <Message>
     <Property Name="foo" value="updated" xdt:Locator=Match(Name) xdt:Transform="Replace" />
  </Message>
</Mesasges>

I can remove all the elements by replacing the Transform=Replace with a Transform=RemoveAll - any ideas how I can achieve something similar to replace all the values?

like image 813
Sean Bedford Avatar asked Sep 28 '11 04:09

Sean Bedford


People also ask

What is xdt Transform?

XDT is a simple and straight forward method of transforming the web. config during publishing/packaging. Transformation actions are specified using XML attributes defined in the XML-Document-Transform namespace, that is mapped to the xdt prefix.

What is Web config transformation?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

How do I rename a web config transform?

If you are using the extension Configuration Transform go to Build > Configuration Manager and find the Configuration dropdown for the project of which you want to change the app config. You can then select the edit and rename the build configurations for that project.


1 Answers

It seems like Transform:Replace only replaces the first matched element from the documentation on msdn: ...If more than one element is selected, only the first selected element is replaced. I solved this issue by using a combination of Match-Conditions and SetAttributes, something like:

<Messages>
  <Message>
    <Property value="updated" xdt:Locator=Condition(@Name='foo') xdt:Transform="SetAttributes(value)" />
  </Message>
</Messages>
like image 52
Emil G Avatar answered Nov 13 '22 04:11

Emil G