【发布时间】:2020-11-06 11:17:26
【问题描述】:
我正在使用 PowerShell 来自定义部署,我需要手动检查一个 web.config 是否存在某个程序集的特定 bindingRedirect,我需要添加它以防万一。
我找到了很多示例和材料,但我很难检测是否存在绑定重定向以及创建具有嵌套节点和属性的实际元素。
网络配置(相关部分):
<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>
我试过了:
$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"]'
以上方法都无法让元素在 if 语句中使用。
【问题讨论】:
标签: powershell web-config devops