Joe Cartano
Joe Cartano

Reputation: 3037

re-evaluate an msbuild item group

I have an item group that includes a location which may or may not contain files. If there are no files present at the point the item group is declared, is it possible to re-evaluate the item group at a later time to pick up files that may have been generated in the new location, or will I have to declare an identical item group at this time and use that?

Upvotes: 3

Views: 1647

Answers (3)

C.J.
C.J.

Reputation: 16081

You can re-define the ItemGroup by first removing the items, and the re-including the items:

<Target Name="Later on" >
   <ItemGroup>
      <ClCompile Remove="@(ClCompile)" />
      <ClCompile Include="something here of your choice" />
   </ItemGroup>
</Target>

Or if you don't want nor need to remove items, you can always simply append or add to the previously existing item group:

<Target Name="Later on" >
   <ItemGroup>
      <ClCompile Include="Add Even more stuff" />
   </ItemGroup>
</Target>

Upvotes: 0

Brian Kretzler
Brian Kretzler

Reputation: 9938

Item groups declared statically (outside of a Target, as a child element of the ) will be evaluated when the file is loaded. Item groups declared dynamically (within a <Target>) will be evaluated at the moment the execution passes through the target. For cases where the files are created during the build, you really should use a dynamic Item group.

Upvotes: 9

Benjamin Baumann
Benjamin Baumann

Reputation: 4065

I think you will have to create a new itemgroup. They are evaluated once and the value is saved, not the formula used to select files. Thus you can't "re-evaluate" these items.

Upvotes: 4

Related Questions