1

MSBuild Community Tasks の Nightly ビルド 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>

それをしないようにするにはどうすればよいですか?

4

1 に答える 1

2

簡単に言えば、できません。置換ファイルのノードに名前空間がある場合でも、置換タスクは常に空の名前空間を使用します。

参照: 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"
      />
于 2009-08-21T09:09:21.557 に答える