jer*_*ome 2 msbuild xpath xml-namespaces
newVersion元素中 属性的 XPATH 是什么
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Linq" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.5.0" newVersion="2.2.5.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
我已经尽力自己做。但是不知道如何为具有命名空间的元素获取 XPATH。它非常混乱。有人请给我一个XPATH。
我想出的 XPATH 是
/configuration/runtime/assemblyBinding/dependentAssembly[2]/bindingRedirect[@newVersion='2.2.5.0']/@newVersion
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="1" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Interfaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect name="Test1" oldVersion="0.0.0.0-2.2.5.0" newVersion="2.2.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Linq" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.5.0" newVersion="2.2.5.0" />
</dependentAssembly>
</assemblyBinding>
Run Code Online (Sandbox Code Playgroud)
正确的 xpath 是
路径:
/configuration/runtime/ns:assemblyBinding/ns:dependentAssembly[ns:assemblyIdentity[@name='System.Reactive.Linq']]/ns:bindingRedirect/@newVersion
ns命名空间在哪里urn:schemas-microsoft-com:asm.v1
我在项目文件中的 MSBuild 任务中使用 XmlPoke 任务来修改绑定重定向。与 XmlPoke 任务一起,代码如下所示:
<XmlPoke XmlInputPath="$(DestXmlFiles)"
Namespaces="<Namespace Prefix='ns' Uri='urn:schemas-microsoft-com:asm.v1' Name='DoNotKnowWhatThisIsFor-ButItIsRequired' />"
Query="/configuration/runtime/ns:assemblyBinding/ns:dependentAssembly[ns:assemblyIdentity[@name='System.Reactive.Linq']]/ns:bindingRedirect/@newVersion"
Value="$(BUILD_NUMBER)"/>
Run Code Online (Sandbox Code Playgroud)