What is the XPATH for attribute newVersion
in the element
<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>
I have tried my best to do it by myself. But don't know how to get XPATH for elements with namespace. Its very confusing. Somebody please provide me a XPATH.
XPATH which I came up with is
/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>
In XSLT 1.0 you must declare namespaces with a prefix in order to be able to use them in XPath.
For example (wrapped for legibility):
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:asm="urn:schemas-microsoft-com:asm.v1"
>
<xsl:template match="/">
<xsl:value-of select="
/configuration/
runtime/
asm:assemblyBinding/
asm:dependentAssembly[2]/
asm:bindingRedirect[@newVersion = '2.2.5.0']/@newVersion
" />
</xsl:template>
</xsl:stylesheet>
However, you don't have to specify the entire path, you could take shortcuts:
<xsl:value-of select="
//asm:assemblyIdentity[@name='System.Reactive.Linq']/
asm:bindingRedirect[@newVersion = '2.2.5.0']/@newVersion
" />
The right xpath is
XPATH:
/configuration/runtime/ns:assemblyBinding/ns:dependentAssembly[ns:assemblyIdentity[@name='System.Reactive.Linq']]/ns:bindingRedirect/@newVersion
Where ns
is the namespace urn:schemas-microsoft-com:asm.v1
I use a XmlPoke Task in the MSBuild tasks in the project file to modify the binding redirect.
Together with a XmlPoke Task the code goes like this:
<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)"/>