Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
847 views
in Technique[技术] by (71.8m points)

msbuild - How do you filter an ItemGroup?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...