0

如何使用 MSbuild 任务在 msbuild 项目之间传递项目组。我有一个 Msbuild 任务,如下所示

<Target Name ="test">
    <MSBuild Projects="New.proj" Targets="mytarget"
            Properties="Itemproperty=@(Item->'%(FullPath)')">
    </MSBuild>
</Target>

其中“项目”是项目组。但我收到如下错误。

 error MSB4012: The expression "Itemproperty=@(Item->'%(FullPath)')" cannot be used in   this context. Item lists cannot beconcatenated with other strings where an item list is     expected. Use a semicolonto separate multiple item lists.

谢谢

4

1 回答 1

0

你能把它“压扁”成一个大的长(单)弦吗?

例子:

   <PropertyGroup>
        <MySuperLongString>@(MyIncludeFiles->'&quot;%(fullpath)&quot;')</MySuperLongString>
    </PropertyGroup>

这里还有一些“选项”

<Message Text="The below items are good when you need to feed command line tools, like the console NUnit exe.  Quotes around the filenames help with paths that have spaces in them. "/>
<Message Text="I found this method initially from : http://pscross.com/Blog/post/2009/02/22/MSBuild-reminders.aspx       Thanks Pscross! "/>
<Message Text="   "/>
<Message Text="   "/>



<Message Text="Flat list, each file surrounded by quotes, with semi colon delimiter: "/>
<Message Text="          @(MyIncludeFiles->'&quot;%(fullpath)&quot;')"/>
<Message Text="   "/>
<Message Text="   "/>



<Message Text="Flat list, each file surrounded by quotes, no comma (space delimiter): "/>
<Message Text="          @(MyIncludeFiles->'&quot;%(fullpath)&quot;' , ' ')"/>
<Message Text="   "/>
<Message Text="   "/>


<Message Text="Flat list, each file surrounded by quotes, with comma delimiter: "/>
<Message Text="          @(MyIncludeFiles->'&quot;%(fullpath)&quot;' , ',')"/>
<Message Text="   "/>
<Message Text="   "/>





<Message Text="List of files using special characters (carriage return)"/>
<Message Text="@(MyIncludeFiles->'&quot;%(fullpath)&quot;' , '%0D%0A')"/>
<Message Text="   "/>
<Message Text="   "/>

完整示例如下:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="AllTargetsWrapper" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <Target Name="AllTargetsWrapper">
        <CallTarget Targets="FunWithFilesTask" />
    </Target>


    <PropertyGroup>
        <WorkingCheckout>.</WorkingCheckout>
    </PropertyGroup>


                <!--    =====================================================                      -->

                <!--

              See:
              http://msdn.microsoft.com/en-us/library/ms164313.aspx

            *Identity    Value for the item specified in the Include attribute.
            *Filename   Filename for this item, not including the extension.
            *Extension  File extension for this item.
            *FullPath   Full path of this item including the filename.
            *RelativeDir    Path to this item relative to the current working directory.
            *RootDir    Root directory to which this item belongs.
            RecursiveDir    Used for items that were created using wildcards. This would be the directory that replaces the wildcard(s) statements that determine the directory.
            *Directory  The directory of this item.
            AccessedTime    Last time this item was accessed.
            CreatedTime     Time the item was created.
            ModifiedTime    Time this item was modified.   
              -->


    <Target Name="FunWithFilesTask">


        <ItemGroup>
            <MyExcludeFiles Include="$(WorkingCheckout)\**\*.doesnotexist" />
        </ItemGroup>

        <ItemGroup>
            <MyIncludeFiles Include="$(WorkingCheckout)\**\*.*" Exclude="@(MyExcludeFiles)" />
        </ItemGroup>  



        <PropertyGroup>
            <MySuperLongString>@(MyIncludeFiles->'&quot;%(fullpath)&quot;')</MySuperLongString>
    </PropertyGroup>  

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


    <Message Text="The below items are good when you need to feed command line tools, like the console NUnit exe.  Quotes around the filenames help with paths that have spaces in them. "/>
    <Message Text="I found this method initially from : http://pscross.com/Blog/post/2009/02/22/MSBuild-reminders.aspx       Thanks Pscross! "/>
    <Message Text="   "/>
    <Message Text="   "/>



    <Message Text="Flat list, each file surrounded by quotes, with semi colon delimiter: "/>
    <Message Text="          @(MyIncludeFiles->'&quot;%(fullpath)&quot;')"/>
    <Message Text="   "/>
    <Message Text="   "/>



    <Message Text="Flat list, each file surrounded by quotes, no comma (space delimiter): "/>
    <Message Text="          @(MyIncludeFiles->'&quot;%(fullpath)&quot;' , ' ')"/>
    <Message Text="   "/>
    <Message Text="   "/>


    <Message Text="Flat list, each file surrounded by quotes, with comma delimiter: "/>
    <Message Text="          @(MyIncludeFiles->'&quot;%(fullpath)&quot;' , ',')"/>
    <Message Text="   "/>
    <Message Text="   "/>


    <Message Text="List of files using special characters (carriage return)"/>
    <Message Text="@(MyIncludeFiles->'&quot;%(fullpath)&quot;' , '%0D%0A')"/>
    <Message Text="   "/>
    <Message Text="   "/>



</Target>


</Project>
于 2013-10-16T20:50:00.867 回答