MSBuild:通过 Zip/Copy 任务添加/复制空文件夹

发布于 2024-07-25 07:35:41 字数 105 浏览 2 评论 0原文

我正在尝试创建复制/压缩一个包含空文件夹的预编译网站(预编译后)。 看起来空文件夹未包含在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凌乱心跳 2024-08-01 07:35:41

我不认为这是最优雅的解决方案,但我们之前所做的是,在解决方案中创建一个文件夹,以及一个名为 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.

聆听风音 2024-08-01 07:35:41

创建项目时,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

伴我心暖 2024-08-01 07:35:41

对于仅复制空文件夹,您可以使用 exec 任务来调用 RoboCopy。 您可以指定参数 /MIR,它将镜像您尝试复制的整个树,包括空文件夹。

示例:

<Exec Command="robocopy "$(SourceLocation)\" "$(TargetLocation)\" /MIR" IgnoreExitCode="true" />

类似地,您可以使用 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:

<Exec Command="robocopy "$(SourceLocation)\" "$(TargetLocation)\" /MIR" IgnoreExitCode="true" />

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.

秋风の叶未落 2024-08-01 07:35:41

这可能有点棘手,但我认为如果所有文件和文件夹都位于公共根目录中并且您压缩该根文件夹而不使用通配符(仅使用“.”),则它会起作用:

<PropertyGroup>
    <SourcePath>.\path\to\rootFolder</SourcePath>
    <FinalZipFileName>.\path\to\destination\myzip.zip</FinalZipFileName>
</PropertyGroup>

<Target Name="MyApplicationZip" >
    <Zip ZipFileName="$(FinalZipFileName)" WorkingDirectory="$(SourcePath)" Files="$(SourcePath)\." ZipLevel="9" />
</Target>

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 '.'):

<PropertyGroup>
    <SourcePath>.\path\to\rootFolder</SourcePath>
    <FinalZipFileName>.\path\to\destination\myzip.zip</FinalZipFileName>
</PropertyGroup>

<Target Name="MyApplicationZip" >
    <Zip ZipFileName="$(FinalZipFileName)" WorkingDirectory="$(SourcePath)" Files="$(SourcePath)\." ZipLevel="9" />
</Target>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文