MSBuild:通过 Zip/Copy 任务添加/复制空文件夹
我正在尝试创建复制/压缩一个包含空文件夹的预编译网站(预编译后)。 看起来空文件夹未包含在 CreateItem 任务之后的项目列表中。 我如何处理空文件夹?
谢谢
I'm trying to create copy/zip a pre-compiled site which is contains empty folders(after pre-compilation). Looks like empty folders is not included to the list of items after CreateItem task.
How I can care of empty folders?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不认为这是最优雅的解决方案,但我们之前所做的是,在解决方案中创建一个文件夹,以及一个名为 placeholder.txt 或类似文件的文本文件,并将文本文件的属性设置为包含在构建中。 结果是您想要的文件夹中包含您不想要的文件。 然后,我们在压缩之前删除 placeholder.txt 文件,所有这些都在构建脚本中。
虽然不优雅,但它适合我们的场景。
I don't feel that this is the most elegant solution, but what we have done before is, creating a folder in the solution, and a text file called placeholder.txt or something similar, and the setting the properties of the text file to be included in the build. The result is a folder where you want it containing a file that you don't want. We then delete the placeholder.txt file before we zip it up, all within the build script.
Not elegant but it does the job for our scenario.
创建项目时,MSBuild 不会选取空文件夹。 如果您想使用任务(例如 MSBuild 扩展包 中的 FindUnder 任务)能够将空文件夹放入项目中。
Sayed Ibrahim Hashimi
我的书:Microsoft 构建引擎内部:使用 MSBuild 和 Team Foundation Build
MSBuild will not pick up empty folders when creating items. You will have to use a task (like the FindUnder task from the MSBuild Extension Pack) if you want to be able to place empty folders into an item.
Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build
对于仅复制空文件夹,您可以使用 exec 任务来调用 RoboCopy。 您可以指定参数 /MIR,它将镜像您尝试复制的整个树,包括空文件夹。
示例:
类似地,您可以使用 exec 任务调用具有命令行界面的压缩实用程序,以实现空文件夹的压缩。
For just copying empty folders you can use an exec task to call RoboCopy. You can specify the argument /MIR which will mirror the entire tree you are trying to copy, including empty folders.
Example:
Similarly, you could use an exec task to call a compression utility that has a command line interface to achieve the zip with empty folders.
这可能有点棘手,但我认为如果所有文件和文件夹都位于公共根目录中并且您压缩该根文件夹而不使用通配符(仅使用“.”),则它会起作用:
It may be a little tricky, but I think it works if all your files and folders are in a common root and you zip that root folder without using wildcards (just using '.'):