MSBuild - 如何复制可能存在或可能不存在的文件? [英] MSBuild - how to copy files that may or may not exist?

查看:175
本文介绍了MSBuild - 如何复制可能存在或可能不存在的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我需要在MSBuild脚本中复制几个特定的​​文件,但它们可能存在也可能不存在。如果他们不存在它很好,我不需要他们。但是标准的< copy> 任务在找不到列表中的每个项目时都会抛出一个错误...

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...

推荐答案

使用复制任务中的存在条件。

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)')"/>

这篇关于MSBuild - 如何复制可能存在或可能不存在的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆