Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild - how to copy files that may or may not exist?

Tags:

copy

msbuild

I have a situation where I need to copy a few specific files in a MSBuild script, but they may or may not exist. If they don't exist it's fine, I don't need them then. But the standard <copy> task throws an error if it cannot find each and every item in the list...

like image 949
Vilx- Avatar asked Feb 04 '09 15:02

Vilx-


1 Answers

Use the Exists condition on Copy task.

<CreateItem Include="*.xml">   <Output ItemName="ItemsThatNeedToBeCopied" TaskParameter="Include"/> </CreateItem>  <Copy SourceFiles="@(ItemsThatNeedToBeCopied)"       DestinationFolder="$(OutputDir)"       Condition="Exists('%(RootDir)%(Directory)%(Filename)%(Extension)')"/> 
like image 180
Julien Hoarau Avatar answered Oct 21 '22 03:10

Julien Hoarau