Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild: Copy files (if changed) and then do an action (only if files were updated)

Tags:

msbuild

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>
like image 413
Daniel Fortunov Avatar asked May 14 '09 16:05

Daniel Fortunov


1 Answers

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

Sayed Ibrahim Hashimi

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build

like image 111
Sayed Ibrahim Hashimi Avatar answered Sep 19 '22 01:09

Sayed Ibrahim Hashimi