XmlMassUpdate - 如何不添加 xmlns?

发布于 2024-08-03 06:24:28 字数 1229 浏览 4 评论 0原文

我正在使用 MSBuild 社区任务的 Nightly build 1.3.0.477,但我遇到了 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>

我如何告诉它不要这样做?

I'm using Nightly build 1.3.0.477 of MSBuild Community Tasks and I'm having problem with XmlMassUpdate.

Here's what I want to do:

for each project, if it does not reference CommonAssemblyInfo.cs file, add that reference.

I'm doing it like this:

<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" />

my substitution file looks like this:

<ItemGroup>
    <Compile Include="..\..\CommonAssemblyInfo.cs" >
        <Link>Properties\CommonAssemblyInfo.cs</Link>
    </Compile>
</ItemGroup>

the issue is, when I run the target, it adds empty xmlns to the Link tag, which is illegal.

<ItemGroup>
<Compile Include="Class1.cs">
  <Link xmlns="">Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

How do I tell it not to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↘紸啶 2024-08-10 06:24:28

简而言之,您不能,即使替换文件的节点具有命名空间,替换任务也始终使用空命名空间。

请参阅: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"
      />

The short answer is you can't, the replace task always uses an empty namespace even if the substitution file's node has a namespace.

see: line 380 in XmlMassUpdate.cs destinationParentNode.AppendChild(mergedDocument.CreateNode(XmlNodeType.Element, nodeToModify.Name, String.Empty)

As an alternative you could use the XSLT task to transform the xml file.

I've included a basic example of how this might be done, but I'm not particularly proficient with XSLT so its a little hacked together.

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

And in the build file.

<Xslt Inputs="input.xml"
      Output="output.xml"
      Xsl="transform.xslt"
      />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文