MSBuild - recursive move/copy filed under a directory to the destination folder
来源:互联网 发布:placeholder.js 编辑:程序博客网 时间:2024/05/16 06:37
It is a very common use case to copy files under one directory to another but keep the structure of the files copied.
You can do with some external command such as xcopy and wrap it in a task in MSBuild, however, MSBulid does porvide some built-in task for copying and moving files. See theMSBuild Built-in tasks here
As discussed in this post: How to : recursively Copy Files Using the <Copy> Task.
We know we can use something like this:
<ItemGroup> <Compile Include=".\**\*.cs" /> </ItemGroup><Copy SourceFiles="@(Compile)" DestinationFolder="c:\foocopy\%(RecursiveDir)"></Copy>
This is a new way of using the MSBuild task/target.. the syntax above basically instruct to expand and execute the command once for each of the elements in the Compile item group. This is part ofadvanced MSBuild concept, which is calledMSBuild Batching.. In this special case, it is using the Task Batching....
A more traditional way is like this:
<ItemGroup> <SourceFiles Include="$(SOURCECODE_ROOT)$(FolderName)\core\mds\WinRel\**\*.dll" /> <SourceFiles Include="$(SOURCECODE_ROOT)$(FolderName)\core\WinRel\**\*.dll" /> <SourceFiles Include="$(SOURCECODE_ROOT)$(FolderName)\core\WinRel\**\*.exe" /> <SourceFiles Include="$(SOURCECODE_ROOT)$(FolderName)\core\WinRel\**\*.tlb" /> <SourceFiles Include="$(SOURCECODE_ROOT)$(FolderName)\core\WinRel\**\*.ocx" /> </ItemGroup><Copy SourceFiles="@(SourceFiles)" DestinationFiles="@(SourceFiles->'$(EXECUTABLES_ROOT)$(FolderName)\$(BuildLevel)\%(RecursiveDir)%(Filename)%(Extension)')" />
The key to the solution is the special use of the MSBuild Items, the % notation start something which is called the Metadata of the Item, and the syntax of
@(SourceFiles->'$(EXECUTABLES_ROOT)$(FolderName)\$(BuildLevel)\%(RecursiveDir)%(Filename)%(Extension)')
I happen to do some task of moving files from one directory to another, please see my code below.
<Target Name="CopyDebugOutput" Condition="'$(Configuration)'=='Debug'"> <PropertyGroup> <DestinationFolder>$(OutDir)..\..\.debug\$(FrameworkSpecializedFolder)</DestinationFolder> </PropertyGroup> <ItemGroup> <SourceFiles Include="$(OutDir)**\*" /> </ItemGroup> <Message Text="DestinationFolder = $(DestinationFolder)" /> <Message Condition="'$(CoronaVerbose)'!='False' And !Exists($(DestinationFolder))" Text="Making $(DestinationFolder)" /> <MakeDir Condition="!Exists($(DestinationFolder))" Directories="$(DestinationFolder)" /> <Message Condition="'$(CoronaVerbose)' != 'False'" Text="Moving from $(OutDir) to $(DestinationFolder)" /> <Move SourceFiles="@(SourceFiles)" DestinationFiles="@(SourceFiles->'$(DestinationFolder)\%(RecursiveDir)%(Filename)%(Extension)')" /> </Target>
- MSBuild - recursive move/copy filed under a directory to the destination folder
- unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder
- Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder
- Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder.
- 解决方法Android 4.0:Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder.
- Android 4.0:Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder.
- 报错“Unable to find a 'userdata.img' file for ABIarmeabi to copy into the AVD folder.”
- 关于Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder的错误
- “Unable to find a 'userdata.img' file for ABIarmeabi to copy into the AVD folder.” 错误解决方案
- 创建虚拟机错误解决:Unable to find a 'userdata.img' file for ABI x86 to copy into the AVD folder.
- 报错“Unable to find a 'userdata.img' file for ABIarmeabi to copy into the AVD folder.”
- Move a user's home directory via the command line
- copy a cv::Mat image (source) to a ROI of another (Destination) cv::Mat image
- Android问题集锦之九:Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder.
- android 创建4.0的模拟器时提示Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder
- destination exists and is not a directory
- Eclipse中创建Maven项目时,报错提示:“a pom xml file already exists in the destination folder ”
- Hadoop copy a directory
- Android控件之SlidingDrawer(滑动式抽屉)详解与实例
- gbk转为utf8乱码分析
- 计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接
- windows 目录表示(上级目录和下级目录)
- java发送邮件
- MSBuild - recursive move/copy filed under a directory to the destination folder
- google svn 服务器使用(免费SVN服务器)
- Linux 增加Zydas WiFi模块
- 阅读log4cplus源代码过程中的小知识点整理(持续更新)
- 自定义Android Toast
- Linux进程调度算法分析
- ScheduledExecutorService接口的学习和使用
- pthread_create
- log4j配置祥解