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...
views:
1024answers:
4
A:
I know little of MSBuild but I know you can make custom tasks. Perhaps you can subclass the task and first check if the file exists.
Brian Ensink
2009-02-04 15:37:28
+8
A:
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)')"/>
madgnome
2009-02-04 15:38:50
Thanx! I had forgotten about these! :)
Vilx-
2009-02-04 15:51:50
A:
The easiest would be to use the ContinueOnError flag http://msdn.microsoft.com/en-us/library/7z253716.aspx
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<MySourceFiles Include="a.cs;b.cs;c.cs"/>
</ItemGroup>
<Target Name="CopyFiles">
<Copy
SourceFiles="@(MySourceFiles)"
DestinationFolder="c:\MyProject\Destination"
ContinueOnError="true"
/>
</Target>
</Project>
But if something else is wrong you will not notice it. So the condition exist from madgnome's answer would be better.
KeesDijk
2009-02-04 15:50:29
A:
It looks like you can mark MySourceFiles as SkipUnchangedFiles="true" and it won't copy the files if they already exist.
daub815
2009-08-25 16:53:42