如果您使用的是 MSBuild 4.0 或更高版本......请使用(内置)Xml Peek。
如何使用XmlPeek任务? https://stackoverflow.com/questions/2688239/how-to-use-xmlpeek-task
如果您使用的是 4.0 之前的版本,请使用 Msbuild 社区任务中的 XmlReader。
https://github.com/loresoft/msbuildtasks https://github.com/loresoft/msbuildtasks
这是一个 ~Peek 示例:
<Target Name="ReadXmlPeekValue">
<!-- you do not need a namespace for this example, but I left it in for future reference -->
<XmlPeek Namespaces="<Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/>"
XmlInputPath=".\Parameters.xml"
Query="/parameters/setParameter[@name='MyConnectionStringParameter']/@value">
<Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>
<Message Text="@(Peeked)"/>
<XmlPeek Namespaces="<Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/>"
XmlInputPath=".\Parameters.xml"
Query="/parameters/setParameter[@name='MyConnectionStringParameter']/@value">
<Output TaskParameter="Result" PropertyName="PeekedSingle" />
</XmlPeek>
<Message Text="$(PeekedSingle)"/>
</Target>
如果您需要命名空间,请注意 XML 命名空间必须是 HTML 编码的。
基于这个简单示例的示例:((还显示 XmlPoke))
http://yentran.org/blog/2012/05/11/modifying-config-file-in-an-msbuild-project/ http://yentran.org/blog/2012/05/11/modifying-config-file-in-an-msbuild-project/
使用“Peek”时,即使使用 msbuild.exe(来自 %WINDIR%\Microsoft.NET\Framework\v4.0.30319),您必须指定 the 工具版本.
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >