tags:

views:

628

answers:

2

I've got an <ItemGroup /> in MSBuild that contains a list of files. I know that you can apply a tranform to the item group when executing tasks, but I'd like to pre-transform the group into another group...an example will probabbly make it more clear.

<ItemGroup>
    <File Include="One.cs" />
    <File Include="Two.cs" />
</ItemGroup>

If I wanted to some sort of copy opperation I could do this:

<Copy SourceFiles="@(File)" 
      DestinationFiles="@(File -> '%Filename''.out')"
      />

Which results in two files called One.out and Two.out being created. What I'd like to do is transform the File group to an OutputFile group using the transform.

<ItemGroup>
    <OutputFile Include="@(File->'%Filename''.out')" />
</ItemGroup>

I've tried the above syntax, but it doesn't actually perform a transform. Instead the @(OutputFile) group contains the text "@(File->'%Filename''.out')".

Has anyone else tried to do this? What syntax would I use to get the desired output group?

+3  A: 

Umm...so turns out I've got a typo in the syntax. It should have been:

<ItemGroup>    
    <OutputFile Include="@(File->'%(Filename)''.out')" />
</ItemGroup>

Notice the parenthesis around Filename.

Paul Alexander
A: 

You should batch instead of transform the itemgroup. Like in this way:

<ItemGroup>
  <OutputFile Include="%(File.Filename).out" />
</ItemGroup>

But what's the use? Goodluck!

Dries