none
Can ItemGroup be refreshed?

    Question

  • I have a MSBuild project which creates some files, and then ZIPs them up in to an archive. This is a simplification, but let's say I have this ItemGroup to specify all of the files that I want in the archive:

    <ItemGroup>
      <ArtifactFiles Include="**/*.dll"/>
    </ItemGroup>

    And I have this target to build the DLL's.

    <Target Name="compile">
      <MSBuild Projects="src/App.sln" />
    </Target>

    I then have this target to ZIP up these DLL's

    <Target Name="artifacts" DependsOnTargets="compile">
      <Zip Files="@(ArtifactFiles)" ZipFileName="Artifacts.zip" />
    </Target>

    I build the target like this:

    msbuild /t:artifacts

    My problem is the ArtifactFiles value seems to be set when the file is first loaded, and at that time the compile target has not yet been run, so the item is empty. The ZIP archive is then empty even though the artifacts were properly compiled.

    Is there a way to refresh the item, or maybe delay it from being evaluated until after the compile target is run?

    Friday, January 13, 2006 8:35 PM

Answers

  • I hate it when I figure out the answer just after I post the question. For those of you that care to know the answer here it is:

    <Target Name="artifact" DependsOnTargets="SnagVersionNumber">
      <
    CreateItem Include="artifacts/**/*" >
        <
    Output TaskParameter="Include" ItemName="ArtifactFiles"/>
      </
    CreateItem>
      <
    Zip Files="@(ArtifactFiles)" ZipFileName="Artifacts.zip" />
    </
    Target>

    There's also no need for the top level ItemGroup.

     

    Friday, January 13, 2006 8:51 PM

All replies

  • I hate it when I figure out the answer just after I post the question. For those of you that care to know the answer here it is:

    <Target Name="artifact" DependsOnTargets="SnagVersionNumber">
      <
    CreateItem Include="artifacts/**/*" >
        <
    Output TaskParameter="Include" ItemName="ArtifactFiles"/>
      </
    CreateItem>
      <
    Zip Files="@(ArtifactFiles)" ZipFileName="Artifacts.zip" />
    </
    Target>

    There's also no need for the top level ItemGroup.

     

    Friday, January 13, 2006 8:51 PM
  • a daysaver ! Thanks!
    Sunday, June 23, 2013 10:19 AM
  • You can use an ItemGroup within the target instead of using CreateItem.

    Mike


    Visual Studio ALM MVP | ALM Ranger
    My Blog | MSBuild Extension Pack | MSBuild Explorer

    Monday, June 24, 2013 7:29 AM
    Moderator