我们使用 MSBuild 来运行一个项目,其中包括通过 Community Tasks 包中的 XMLQuery 任务从 XML 文件中读取一些值。它在 MSBuild 3.5 下运行良好,但在 4.0 下运行时失败并显示以下消息:
错误 MSB4018:“XmlQuery”任务意外失败。System.Xml.XmlException:名称不能以“%”字符开头,十六进制值 0x25。第 1 行,位置 2。在 System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) 在 System.Xml.XmlTextReaderImpl.Throw(Exception e) 在 System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32&colonPos) 在 System.Xml.XmlTextReaderImpl.ParseElement() 在 System.Xml.XmlTextReaderImpl.ParseDocumentContent() 在 System.Xml.XmlTextReaderImpl.Read() 在 System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader 阅读器,XmlSpace 空间)在 System.Xml.XPath.XPathDocument..ctor(TextReader textReader) 在 MSBuild.Community.Tasks.Xml.XmlQuery.loadXmlContent() 在 MSBuild.Community.Tasks.Xml.XmlQuery.Execute() 在 Microsoft.Build.BackEnd。任务执行主机。
用于从构建目标中调用 XMLQuery 的代码:
<!-- Read XML report -->
<ReadLinesFromFile File="coverageXML\symbolmodule.xml">
<Output TaskParameter="Lines" ItemName="XmlReportLines" />
</ReadLinesFromFile>
<!-- Get number of visited sequence points -->
<XmlQuery Lines="@(XmlReportLines)" XPath="/trendcoveragedata/stats/@vsp">
<Output TaskParameter="Values" PropertyName="VisitedSequencePoints" />
</XmlQuery>
我只是不明白出了什么问题。XML 文件完全有效,并且 XMLQuery 中指定的 XPath 应该返回一个值(并且总是有)。我在任何地方都找不到一个 % 字符。
我不知道如何以及从哪里开始解决这个问题......任何正确方向的指针表示赞赏。