2

We use MSBuild to run a project which, among many other things, reads some values from an XML file by means of the XMLQuery task from the Community Tasks package. It worked fine under MSBuild 3.5 but when run under 4.0 it fails with the following message:

error MSB4018: The "XmlQuery" task failed unexpectedly. System.Xml.XmlException: Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) at System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos) at System.Xml.XmlTextReaderImpl.ParseElement() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space) at System.Xml.XPath.XPathDocument..ctor(TextReader textReader) at MSBuild.Community.Tasks.Xml.XmlQuery.loadXmlContent() at MSBuild.Community.Tasks.Xml.XmlQuery.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)

The code used to call XMLQuery from within a build target:

<!-- 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>

I just can't understand what's wrong. The XML file is perfectly valid and the XPath specified in the XMLQuery should return a value (and always has). I can't find a single % character anywhere.

I'm not sure how and where to start troubleshooting this issue... Any pointers in the right direction are appreciated.

1
  • 2
    I noticed it's possible to actually debug MSBuild projects using Visual Studio 2010, so I'm going to try and see if that gives any more info
    – Mels
    Commented Jul 28, 2010 at 12:56

1 Answer 1

6

ReadLinesFromFile now (in MSBuild 4.0) returns escaped values. You have to unescape them before running XmlQUery. Like this:

<!-- Read XML report -->
<ReadLinesFromFile File="coverageXML\symbolmodule.xml">
  <Output TaskParameter="Lines" ItemName="XmlReportLinesEscaped" />
</ReadLinesFromFile>
<ItemGroup>
<XmlReportLinesEscaped>
  <Escaped>%(XmlReportLinesEscaped.Identity)</Escaped>
  <Unescaped>$([MSBuild]::Unescape('%(XmlReportLinesEscaped.Identity)'))</Unescaped>
</XmlReportLinesEscaped>
</ItemGroup>
<ItemGroup>
  <XmlReportLines Include="@(XmlReportLinesEscaped->'%(Unescaped)')"></XmlReportLines >
</ItemGroup>
<!-- Get number of visited sequence points -->
<XmlQuery Lines="@(XmlReportLines)" XPath="/trendcoveragedata/stats/@vsp">
  <Output TaskParameter="Values" PropertyName="VisitedSequencePoints" />
</XmlQuery>

Should work.

Greg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.