开发者

Help Updating XML file using MSBuild Extensions 4 with namespaces

I'm having some trouble getting MSBuild extensions 4.0 to update an XML file once a namespace is involved.

When I have a simple XML file with no namespace then fine, but once i attempt to update an xml file that has a namespace set, then nothing happens .. notice there is no error tho.

Here are the simple ones that work fine

    <Project>
      <PropertyGroup>
        <ApplicationVersion>5.1.500.16</ApplicationVersion>
      </PropertyGroup>
      <PropertyGroup>
        <ApplicationVersion>old</ApplicationVersion>
      </PropertyGroup>
    </Project>

and project file

    <Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <TPath>C:\Program Files\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks</TPath>
            <AssemblyVersion>5.1.500.18</AssemblyVersion>
        </PropertyGroup>
        <Import Project="$(TPath)"/>
        <Target Name="Default">
            <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement"  "  File="c:\build\test.csproj"  XPa开发者_Go百科th="/Project/PropertyGroup[1]/ApplicationVersion" />
        </Target>
    </Project>

Wheras these dont do anything !

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://mynamespace">
      <PropertyGroup>
        <ApplicationVersion>5.1.500.16</ApplicationVersion>
      </PropertyGroup>
      <PropertyGroup>
        <ApplicationVersion>old</ApplicationVersion>
      </PropertyGroup>
    </Project>

and

    <Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <TPath>C:\Program Files\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks</TPath>
            <AssemblyVersion>5.1.500.18</AssemblyVersion>
        </PropertyGroup>
        <Import Project="$(TPath)"/>
        <ItemGroup>
            <Namespaces Include="Mynamespace">
                <Prefix>me</Prefix>
                <Uri>"http://mynamespace"</Uri>
            </Namespaces>
        </ItemGroup>
        <Target Name="Default">
            <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement"  Namespaces="@(Namespaces)"  File="c:\build\test.csproj"  XPath="//me:Project/PropertyGroup[1]/ApplicationVersion" />
        </Target>
    </Project>

So what's the deal ? what am i missing ? Is it the formatting of the XPath in the second instance ? I've tried all kinds of variations.


Try this:

    <Target Name="Default">
        <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement"  Namespaces="@(Namespaces)"  File="c:\build\test.csproj"  XPath="//me:Project/me:PropertyGroup[1]/me:ApplicationVersion" />
    </Target>

(namespace prefix before each xpath element)


In addition to the advice given in the other answer, remove the quotes from the Uri metadata in the Namespace item.

Note that according to the note for the prefix parameter in the MSDN documentation, specifing the empty string for the Prefix metadata will never work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜