简短的回答是,你不能,即使替换文件的节点有一个命名空间,替换任务也总是使用空的命名空间。
请参见XmlMassUpdate.cs中的第380行
destinationParentNode.AppendChild(mergedDocument.CreateNode(XmlNodeType.Element, nodeToModify.Name, String.Empty)
作为替代方案,您可以使用XSLT任务来转换xml文件。
我已经包括了一个如何做到这一点的基本示例,但我对XSLT不是特别精通,所以它有点拼凑在一起。
<xsl:stylesheet
version="1"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
xmlns:msb="http://schemas.microsoft.com/developer/msbuild/2003"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output indent="yes"
standalone="yes"
method="xml"
encoding="utf-8"
/>
<xsl:template match="/msb:Project/msb:ItemGroup[1]">
<ItemGroup>
<Compile Include="..\..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
</ItemGroup>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
在构建文件中。
<Xslt Inputs="input.xml"
Output="output.xml"
Xsl="transform.xslt"
/>