2

我正在尝试将转换应用于 HTML 文件。转换适用于 div 和 span,但只要我插入 P 标签,它就会失败。

我正在转换的 HTML 文件是:

<!DOCTYPE html>
<html>
  <head>
    <title>STREAM Interactive - UAT</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  </head>
    <body>
          <p>my para</p>
    </body>
</html>

转换文件非常简单:

<html xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
   <head>
     <title xdt:Transform="Replace">TITLEHEADINGHERE</title>
   </head>  

</html>

用于进行转换的项目文件是:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile="C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.Dll"/>

    <PropertyGroup>
        <SourceFile>web.config</SourceFile>
        <TransformFile>web.debug.config</TransformFile>
        <OutputFile>final.config</OutputFile>
    </PropertyGroup>

    <Target Name="GenerateConfigs">
        <Message Text="Beginning Transformation." />
        <Message Text="$(SourceFile)" />
        <TransformXml Source="$(SourceFile)" Transform="$(TransformFile)" Destination="$(OutputFile)" />
        <Message Text="Completed Transformation." />
    </Target>

</Project>

使用的命令是:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe D:\SAM\SAMSite\bin\msbuild-transform-Template.xml /p:SourceFile="C:\temp\buildTest\BlueZone\2.3.10.5\PublishedClickOnce\index.html" /p:TransformFile="D:\SAM\SAMSite\bin\TransformTemplates\clickonce.index.transform.temp" /p:OutputFile="C:\temp\buildTest\BlueZone\2.3.10.5\PublishedClickOnce\index.html.temp"

我得到的输出/错误是:

Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.269]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 02/07/2012 10:54:33.
Project "D:\SAM\SAMSite\bin\msbuild-    transform-Template.xml" on node 1 (default targets).
GenerateConfigs:
  Beginning Transformation.
  C:\temp\buildTest\BlueZone\2.3.10.5\PublishedClickOnce\index.html
  Transforming Source File:     C:\temp\buildTest\BlueZone\2.3.10.5\PublishedClickOnce\index.html
  Transformation succeeded
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018: The "TransformXml" task failed unexpectedly.
D:\SAM\SAMSite\bin\msbuild-transform-    Template.xml(13,3): error MSB4018: System.UriFormatException: Invalid URI: The URI is empty.
D:\SAM\SAMSite\bin\msbuild-transform-    Template.xml(13,3): error MSB4018:    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Web.Publishing.Tasks.TransformXml.Execute()
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)
Done Building Project "D:\SAM\SAMSite\bin\msbuild-transform-Template.xml" (default targets) -- FAILED.

Build FAILED.

"D:\SAM\SAMSite\bin\msbuild-transform-Template.xml" (default target) (1) ->
(GenerateConfigs target) -> 
  D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018: The "TransformXml" task failed unexpectedly.
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018: System.UriFormatException: Invalid URI: The URI is empty.
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Web.Publishing.Tasks.TransformXml.Execute()
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.09

HTML 已被尽可能地精简,以前那里有 div 和 span。有趣的是,如果我给 P 标签一个类,它就可以工作。

我不知道为什么会这样。

编辑

根据@Kieren 的建议,我尝试直接使用 TransformXml 运行。我收到一个新错误:

Data at the root level is invalid. Line 1, position 1.

   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at Microsoft.Web.Publishing.Tasks.XmlAttributePreservationDict.ReadPreservationInfo(String elementStartTag)
   at Microsoft.Web.Publishing.Tasks.XmlAttributePreservationProvider.GetDictAtPosition(Int32 lineNumber, Int32 linePosition)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.XmlFileInfoElement..ctor(String prefix, String localName, String namespaceUri, XmlFileInfoDocument document)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.CreateElement(String prefix, String localName, String namespaceURI)
   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.LoadFromTextReader(TextReader textReader)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.LoadFromFileName(String     filename)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.Load(String filename)
   at QuickTests.TestTransformXml.OpenSourceFile(String sourceFile) in C:\Users\jon\Documents\Visual Studio 2010\Projects\QuickTests\QuickTests\TestTransformXmlTask.cs:line 140
4

1 回答 1

1

根据我提交的错误报告,此问题现已修复。假设它将包含在 MsBuild 的下一个版本中,(不知道什么时候会):

https://connect.microsoft.com/VisualStudio/feedback/details/752279/msbuild-tansform-failure-for-elements-with-only-one-character

于 2012-08-01T09:35:25.147 回答