tags:

views:

834

answers:

1

In MSBuild I can use the Copy task to copy files from one location to another.

I can also use the SkipUnchangedFiles property to specify that files should not be copied if they have not changed.

Is there a standard pattern for predicating a follow-up action on the condition that one or more files were copied?

For example:

  1. Copy any updated deployment scripts
  2. Execute the batch file which runs all the deployment scripts, in the correct order, if and only if one or more of the scripts have changed

One further complication is that I am using the CreateItem task to dynamically generate the list of input files:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CopyAndRun">
  <Target Name="CopyAndRun">
    <CreateItem Include="In\**\*Test*.txt">
      <Output TaskParameter="Include" ItemName="SourceFiles"/>
    </CreateItem>
    <Copy SourceFiles="%(SourceFiles.Identity)" DestinationFolder="Out\%(RecursiveDir)" SkipUnchangedFiles="true" />
    <!-- Only want to execute this if updated files were copied -->
    <Message Text="Running..." />
  </Target>
</Project>
+2  A: 

Hi, You can achieve this with incremental building that is provided out of the box with MSBuild.

Sayed Ibrahim Hashimi
Your book rules the MSBuild World!!!!!! I love it!
Vaccano
Good idea! However, I am using CreateItem to dynamically generate my list of files to copy. Is it still possible to use the incremental building feature in this case? (I've added an example project to my question.)
Daniel Fortunov
Yes this is still possible. Pretty easy actually. Create another target, i.e. SourceFilesItems, and make CopyAndRun depend on that. Then when MSBuild gets to your CopyAndRun it will first execute the dependent targets and after that batching will start when CopyAndRun is actually executed.If you continue to have problems, I can provide you a concrete example.Sayed Ibrahim Hashimi
Sayed Ibrahim Hashimi
By the way, if you are using MSBuild 3.5 then instead of using the CreateItem task you can just declare your items inside targets using the normal ItemGroup syntax.
Sayed Ibrahim Hashimi