I have a target that copies source files to a staging directory, this happens for multiple projects. In a later project, those files are passed into a type of compiler.
Currently that staging directory is not cleaned, so when a source file is deleted, a stale copy lives on in the staging directory.
What's the best way to clean that staging directory of stale files without negatively impacting my incremental build times? (ie. without fully deleting the staging directory each time)
Ended up using this bit of script to clean up files which had been removed from the source, but still exist in the destination:
<Target Name="DeleteStaleFiles">
<!-- Remove stale files (files which have been deleted at the source but still exist in the destination). -->
<ItemGroup>
<SourceFiles Include="@(SourceFiles->'$(Destination)\%(RecursiveDir)%(Filename)%(Extension)')" />
<DestinationFiles Include="$(Destination)**\*.*" />
<StaleFiles Include="@(DestinationFiles)" Exclude="@(SourceFiles)" />
</ItemGroup>
<Message Text="Deleting Stale Files: @(StaleFiles, '%0A')" Condition="'@(StaleFiles->Count())' > 0"/>
<Delete Files="@(StaleFiles)"/>
</Target>