Using MSBuild to zip up multiple project directories

陌路散爱 提交于 2019-12-04 11:07:07

I came up with a workaround - a combination of the MSBuild Extension pack's FileUnder task, to enumerate the ProjectX folders that I want to zip up, and the Exec task invoking 7Zip. The code is:

<MSBuild.ExtensionPack.FileSystem.FindUnder
    TaskAction="FindDirectories"
    Path="$(WebOutputFolder)"
    Recursive="False">
    <Output ItemName="WebsiteFolders" TaskParameter="FoundItems" />
</MSBuild.ExtensionPack.FileSystem.FindUnder>

<Exec Command="7za.exe a -r %22$(OutDir)%(WebsiteFolders.Filename)-$(Configuration)-$(AssemblyFileVersion).zip%22 %22@(WebsiteFolders)\*%22" />

So now each zip file is named after the folder its contents came from (as well as configuration and versioning details), so I'll have files in my output folder named ProjectA-Debug-0.1.2.345.zip etc.

That will most likely be because the native .Net framework zip functionality cannot do nested folders, only files - if the task you are using uses this functionality then you will be out of luck.

Also your syntax for the ZipSource Include="\OutDir\**.*" is slightly wrong, try using <ZipSource Include="\OutDir\**\*.*" instead.

If that doesn't work, try using the Zip task from the MSBuild Extension tasks, it does what you need. (Here is the doco for it).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!