0

我想知道是否可以通过父母传递来阅读孩子。

<configuration>

    <Server>
        <RootDirectory>Temp</RootDirectory>
        <IP>192.168.10.10</IP>
        <Port>350</Port>
        <UserName>USERNAME</UserName>
        <UserPassword>PASSWORD</UserPassword>       
    </Server>

</configuration>

我将阅读节点“服务器”:

<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadElements" File="server.config" XPath="//configuration/Server">
            <Output TaskParameter="Elements" ItemName="Server" />
</MSBuild.ExtensionPack.Xml.XmlFile>

我想显示所有子节点,如下所示:

<Message Text="%(Server.RootDirectory) - %(Server.IP)"/>

有任何想法吗?

4

2 回答 2

0

最后,在 Mike Fourie(解决方案)的帮助下,有一个解决方案。

您需要下载最新的源代码,编译 .sln 并将二进制文件复制到您的文件夹 c:\Program Files\Msbuild\ExtensionPack 以使用属性“ReadChildrenToMetadata”,如下所示:

<configuration>

    <Server>
        <RootDirectory>Temp</RootDirectory>
        <IP>192.168.10.10</IP>
        <Port>350</Port>
        <UserName>USERNAME</UserName>
        <UserPassword>PASSWORD</UserPassword>       
    </Server>

</configuration>

读取元素:

<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadElements" ReadChildrenToMetadata="true" File="Config\ftp.config" XPath="//configuration/Server">
            <Output TaskParameter="Elements" ItemName="Server" />
</MSBuild.ExtensionPack.Xml.XmlFile>

<Message Text="%(Server.RootDirectory) - %(Server.IP)"/>

你会得到:

Temp - 192.168.10.10
于 2013-09-19T06:48:38.013 回答
0
<?xml version="1.0" encoding="utf-8"?>
<Project  ToolsVersion="4.0"  xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">


    <Target Name="AllTargetsWrapped">
        <CallTarget Targets="ReadXmlPeekValue" />
        <CallTarget Targets="ParseIndividualXmls" />
    </Target>   


    <Target Name="ReadXmlPeekValue">
        <!-- you do not need a namespace for this example, but I left it in for future reference -->
        <XmlPeek Namespaces="&lt;Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/&gt;"
             XmlInputPath=".\Parameters.xml" 
             Query="/configuration/Server">
            <Output TaskParameter="Result" ItemName="Peeked" />
        </XmlPeek>

        <Message Text="@(Peeked)"/>

    </Target>   


    <Target Name="ParseIndividualXmls"  Outputs="%(Peeked.Identity)">

        <!-- See http://sstjean.blogspot.com/2006/09/how-to-get-msbuild-to-run-complete.html  -->

        <PropertyGroup>
            <MyXmlSnipplet>%(Peeked.Identity)</MyXmlSnipplet>
        </PropertyGroup>


        <!--
        <Message Text=" MyXmlSnipplet = $(MyXmlSnipplet)  "/>
        -->

        <XmlPeek Namespaces="&lt;Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/&gt;"
             XmlContent="$(MyXmlSnipplet)" 
             Query="/Server/RootDirectory[1]/text()">
            <Output TaskParameter="Result" PropertyName="MyRootDirectory" />
        </XmlPeek>

        <Message Text="  MyRootDirectory = $(MyRootDirectory) "/>


        <XmlPeek Namespaces="&lt;Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/&gt;"
             XmlContent="$(MyXmlSnipplet)" 
             Query="/Server/IP[1]/text()">
            <Output TaskParameter="Result" PropertyName="MyIP" />
        </XmlPeek>

        <Message Text="  MyIP = $(MyIP) "/>     

    </Target>



    <!--
                <configuration>

                    <Server>
                        <RootDirectory>Temp</RootDirectory>
                        <IP>192.168.10.10</IP>
                        <Port>350</Port>
                        <UserName>USERNAME</UserName>
                        <UserPassword>PASSWORD</UserPassword>       
                    </Server>



                    <Server>
                        <RootDirectory>Poopty</RootDirectory>
                        <IP>10.0.1.444</IP>
                        <Port>333</Port>
                        <UserName>Scott</UserName>
                        <UserPassword>Tiger</UserPassword>       
                    </Server>


                </configuration>

-->


</Project>
于 2013-09-18T21:31:09.217 回答