Msbuild 根据目标参数列表复制到多个位置?
我有一个目录想要复制到多个位置。
假设我有
- home.aspx
我想将其复制到
- abc/home.aspx
- def/home.aspx
- ghi/home.aspx
那么我有两个问题:
- 如何定义列表 abc、def、ghi?
- 如何对此列表中的每个元素执行复制任务?
I got a directory I want to copy to a number of locations.
Say I have
- home.aspx
I want to copy it to
- abc/home.aspx
- def/home.aspx
- ghi/home.aspx
so two questions for me:
- How do I define the list abc, def, ghi?
- How do I execute my Copy task with each element of this list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是我整理的一个实际示例,显示了您正在寻找的内容:
Here is an actual example that I put together that shows what you were looking for:
您应该感兴趣的概念是 批处理< /a>.
我在我的博客上介绍了这个确切的场景 http ://www.sedodream.com/PermaLink,guid,5f1e0445-ce3d-4052-ba80-42fd19512d42.aspx
这是该博客文章的文本,您可以在上面的链接下载提到的文件。
今天有人告诉我,一位同事在使用 MSBuild 时遇到了问题。 他告诉我,他正在尝试将一组文件复制到一组不同的服务器。 但问题是他不知道如何在不执行多次复制任务调用的情况下实现这一目标。 我告诉他,他可以使用 MSBuild Batching 来实现这一目标。 批处理是一次对一组项目(批次)执行任务(或目标)的过程。 批次也可以包含单个项目。 因此,在这种情况下,我们需要为他想要部署到的每台服务器执行一次复制。 我创建了一个简单的 msbuild 文件,它以两种不同的方式演示了这一点。 第一种方法使用任务批处理,这可以在测试目标中看到。 另一个使用目标批处理,可以在 DoItCore 目标中看到。 我还创建了一个干净的目标,与批处理无关。
批处理是 MSBuild 的高级主题,肯定会被忽视。 我必须承认我自己对这件事写得不够多而感到内疚。 下面列出了一些很好的批处理资源。
以下是我发布的其他一些与批处理相关的博客文章。
谢谢,
Sayed Ibrahim Hashimi
我的书:Microsoft 构建引擎内部:使用 MSBuild 和 Team Foundation Build
The concept that you should be interested in is known as Batching.
I've covered this exact scenario on my blog at http://www.sedodream.com/PermaLink,guid,5f1e0445-ce3d-4052-ba80-42fd19512d42.aspx
Here is the text of that blog entry, you can download the mentioned files at the link above.
Today someone was telling me about a co-worker who was having issues with MSBuild. He told me that he was trying to copy a set of files to a set of different servers. But the issue was that he didn’t know how to achieve this without performing multiple Copy task invocations. I told him that he could achieve this using MSBuild Batching. Batching is a process of performing a task (or target) on a set of items (batches) at a time. A batch can also include a single item. So in this scenario we need to perform the copy one time for each server that he wanted to deploy to. I’ve created a simple msbuild file which demonstrates this in two different ways. The first way uses task batching, which can bee seen in the Test target. And the other uses Target batching which can be seen in the DoItCore target. I've also created a clean target, which has nothing to do with batching.
Batching is an advanced topic of MSBuild, and is defintely neglected. I have to admit I’m guilty of not writing about it enough myself. There are some good batching resources, they are listed below.
Here are some other batching related blog entries that I've posted.
Thanks,
Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build
有一个项目组,您可以在其中构建此目的地列表(“abc...等)。然后使用此列表调用复制任务(@Destination)。
我相信您会发现如果你搜索它,就会有很多例子。 //keithhill.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&_c=BlogPart&partqs=cat%3dMSBuild
Have an itemgroup where you build up this list of destinations ("<Destination>abc</Destionation>..., etc). Then invoke the copy task with this list (@Destination).
I'm sure you'll find plenty of examples if you search for it. http://keithhill.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&_c=BlogPart&partqs=cat%3dMSBuild
您最好自己将其作为学习练习,而不是将 MSBUILD 视为一个魔术盒。 Patrick Smacchia 的这篇文章 为您提供了所涉及的大部分技术。
You really are best off doing this yourself as a learning exercise, rather than treating MSBUILD as a magic box. This article from Patrick Smacchia gives you most of the techniques involved.