0

I am trying to use Microsoft.Web.XmlTransform.dll to update an xml doc. I need to insert a new assembly element if one with the child element does not have a matching attribute name.

Transform:

<config>
  <assembly xdt:Transform="Insert" xdt:Locator="Condition(./assembly/file/@name!='qux.dll')>
    <file name='qux.dll>
  </assembly>
</config>

Original Config:

<config>
  <assembly>
    <file name='foo.dll>
  </assembly>
  <assembly>
    <file name='bar.dll>
  </assembly>
  <assembly>
    <file name='qux.dll>
  </assembly>
</config>

Output:

<config>
  <assembly>
    <file name='foo.dll>
  </assembly>
  <assembly>
    <file name='bar.dll>
  </assembly>
  <assembly>
    <file name='qux.dll>
  </assembly>
  <assembly>
    <file name='qux.dll>
  </assembly>
</config>

Expected output:

<config>
  <assembly>
    <file name='foo.dll>
  </assembly>
  <assembly>
    <file name='bar.dll>
  </assembly>
  <assembly>
    <file name='qux.dll>
  </assembly>
</config>

I am assuming xdt:Locator="Condition(./assembly/file/@name!='qux.dll') is incorrect, but I can't for the life of me get it working as expected.

SmudgerDan
  • 413
  • 5
  • 16

1 Answers1

0

Cracked it:

<config>
  <assembly xdt:Transform="InsertIfMissing" xdt:Locator="Condition(file/@name='qux.dll')>
    <file name='qux.dll>
  </assembly>
</config>
SmudgerDan
  • 413
  • 5
  • 16