Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
701 views
in Technique[技术] by (71.8m points)

msbuild - XPath for element with namespace

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>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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="&lt;Namespace Prefix='ns' Uri='urn:schemas-microsoft-com:asm.v1' Name='DoNotKnowWhatThisIsFor-ButItIsRequired' /&gt;"
          Query="/configuration/runtime/ns:assemblyBinding/ns:dependentAssembly[ns:assemblyIdentity[@name='System.Reactive.Linq']]/ns:bindingRedirect/@newVersion"
          Value="$(BUILD_NUMBER)"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...