c++visual-c++msbuildechoitemgroup

echo All Elements of an ItemGroup


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?


Solution

  • 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>