Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you filter an ItemGroup?

Tags:

msbuild

I'm trying to create a filtered item group from another one, where the filtered item group will only contain items from the first group that have a specified file extension.

I'm getting the following error:

error MSB4190: The reference to the built-in metadata "Extension" at position 1 is not allowed in this condition "'%(Extension)'=='.sys'".

When I run this:

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

  <ItemGroup>
    <Files Include="X.exe"/>
    <Files Include="Y.sys"/>
  </ItemGroup>

  <ItemGroup>
    <SysFiles Include="%(Files.Identity)" Condition="'%(Extension)'=='.sys'">
    </SysFiles>
  </ItemGroup>

  <Target Name="Go">
    <Message Text="SysFiles=@(SysFiles)"/>
  </Target>

</Project>

Firstly, I can't understand why the meta data isn't allowed at this position? Is it some artificial restriction or unimplemented part of msbuild?

Secondly, what's a concise way of achieving this kind of transform?

Thanks very much.

like image 580
Scott Langham Avatar asked Nov 01 '12 12:11

Scott Langham


1 Answers

Ok, I've found if I specify the ItemGroup SysFiles inside target Go, it will work without error.

like image 151
Scott Langham Avatar answered Oct 19 '22 10:10

Scott Langham