我正在使用晚间构建1.3.0.477的MSBuild社区任务,并且我对XmlMassUpdate有问题。
我想做的是:
对于每个项目,如果它不引用CommonAssemblyInfo.cs文件,则添加该引用。
我就是这样做的
<Message Text="Path is $(MSBuildCommunityTasksPath)" Importance="normal" />
<!---->
<XmlMassUpdate ContentFile="%(DotNetProjects.FullPath)"
ContentRoot="msb:Project/msb:ItemGroup[2]/msb:Compile[1]"
NamespaceDefinitions="msb=http://schemas.microsoft.com/developer/msbuild/2003"
SubstitutionsFile="$(BuildFolder)CommonAssemblyInfo.substitution"
SubstitutionsRoot="ItemGroup/Compile" />
我的替换文件如下所示:
<ItemGroup>
<Compile Include="..\..\CommonAssemblyInfo.cs" >
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
</ItemGroup>问题是,当我运行目标时,会将空的xmlns添加到链接标记中,这是非法的。
<ItemGroup>
<Compile Include="Class1.cs">
<Link xmlns="">Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>我该怎么告诉它不要这么做?
发布于 2009-08-21 09:09:21
简单地说,您不能,替换任务总是使用一个空的名称空间,即使替换文件的节点有一个名称空间。
参见: XmlMassUpdate.cs destinationParentNode.AppendChild(mergedDocument.CreateNode(XmlNodeType.Element, nodeToModify.Name, String.Empty)中的第380行
作为另一种选择,您可以使用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"
/>https://stackoverflow.com/questions/1305833
复制相似问题