Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MsBuild run Exec for every item in a list

Tags:

msbuild

I'm trying to load a list of filenames from a text file and then run an Exec task for each entry retrieved from the text file.

So I have a file, let's call it SomeFile.txt containing the following:

FileA.file
FileB.file
FileC.file

The MsBuild code I have for this looks like this (which doesn't work:)

<Target Name="runScripts">  

    <ItemGroup>
        <scriptsFile Include="SomeFile.txt" />
    </ItemGroup>        

    <ReadLinesFromFile File="@(scriptsFile)">
        <Output TaskParameter="Lines" ItemName="scriptItems" />
    </ReadLinesFromFile>

    <Message Text="Running Exec for each entry..." />           
    <Exec Command="$(someCommand) %(scriptItems)" />

</Target>

This gives me an error saying I need to specify an item name, but if I use anything like %(scriptItems.item) or %(itemname.scriptItems) MsBuild simply puts a blank instead of %(scriptItems).

like image 514
Jaco Pretorius Avatar asked Mar 08 '10 11:03

Jaco Pretorius


1 Answers

Simply need to use %(scriptItems.Identity) to get an item name from the metadata. This is well documented at MSDN.

like image 116
Jaco Pretorius Avatar answered Oct 15 '22 05:10

Jaco Pretorius