I am using PowerShell to customize deployments, I need to manually check if a web.config has a specific bindingRedirect exists for an assembly, and I need to add it in case it doesn't.
I found a lot of example and material but I struggle to both detect if the binding redirect is present and to create the actual element with nested nodes and attributes.
The web config (relevant part):
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Linq" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I tried:
$XML.SelectSingleNode("/configuration/runtime/assemblyBinding[@xmlns='urn:schemas-microsoft-com:asm.v1']/dependentAssembly/assemblyIdentity[@name='System.IO']")
$XML.configuration.runtime.assemblyBinding.dependentAssembly.SelectSingleNode("assemblyIdentity[@name='System.IO']")
Select-Xml -Xml $XML -XPath '//assemblyIdentity[@name="System.IO"]'
None of the above worked to get the element to be used in an if statement.