echo All Elements of an ItemGroup

别说谁变了你拦得住时间么 提交于 2019-12-14 02:28:51

问题


I have an MSBuild ItemGroup and I would like to be able to echo it out in the "Post-Build Event".

However when I try commands like: echo My ItemGroup: @(Foo)

I get the error:

error MSB4164: The value "echo My ItemGroup: @(Foo)" of metadata "Command" contains an item list expression. Item list expressions are not allowed on default metadata values.

I'm not very good with ItemGroups as of yet. Is there a way I can just echo the list of files that Foo contains?


回答1:


You'll want something like:

<ItemGroup>
  <ForcedUsingFilesList Include="c:\path\to\files\*" />
</ItemGroup>
<Target Name="MyTarget">
  <PropertyGroup>
    <MyFiles>
        @(ForcedUsingFilesList->'%(FullPath)')
    </MyFiles>
  </PropertyGroup>
  <Exec>echo $(MyFiles)</Exec>
</Target>



回答2:


Try %(Foo.Identity) instead. That will print just one item from the list, but cause the Task containing it (the Exec I suppose) to loop over the items.

If that doesn't work, be sure to work with the XML file directly rather than the IDE, in case it escapes things or puts in other code we don't see.

(later) It might be like this post, where they lament it is not simple and needs direct editing of the XML anyway. So just change it to a Exec task where the itemlist expression appears in an attribute, not a metadata definition.

It is written that the PostBuildEvent is more of a backward compatibility thing, and the good one to use is the AfterBuild target, that “is able to contain arbitrary MSBuild tasks, including one ore more Exec tasks … it doesn't have a custom UI in the IDE … edit it as XML …” Tip 43 in Brian Kretzler's book.



来源:https://stackoverflow.com/questions/26801753/echo-all-elements-of-an-itemgroup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!