Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 使用MSBuild压缩多个项目目录_.net_Msbuild_Build Automation - Fatal编程技术网

.net 使用MSBuild压缩多个项目目录

.net 使用MSBuild压缩多个项目目录,.net,msbuild,build-automation,.net,Msbuild,Build Automation,作为MSBuild 4.0中构建过程的一部分,我最终得到以下目录结构: \OutDir \ProjectA \File1.dll \File2.dll \File3.exe \ProjectB \Subfolder1 File4.html \File5.dll \File6.dll \File7.exe \ProjectC \File8.dll

作为MSBuild 4.0中构建过程的一部分,我最终得到以下目录结构:

\OutDir
    \ProjectA
      \File1.dll  
      \File2.dll  
      \File3.exe
    \ProjectB
      \Subfolder1
        File4.html
      \File5.dll  
      \File6.dll  
      \File7.exe
    \ProjectC
      \File8.dll  
      \File9.exe
我希望能够为
\OutDir
的每个子文件夹创建一个zip文件。如果我这样做:

<ItemGroup>
  <ZipSource Include="\OutDir\**.*" />
</ItemGroup>

<MSBuild.Community.Tasks.Zip
  Files="@(ZipSource)"
  ZipFileName="OutDir\%(ZipSource.RecursiveDir)ZippedOutput.zip"
  WorkingDirectory="OutDir" />

然后递归地压缩每个子文件夹,这对ProjectA和ProjectC很好,但ProjectB最终会有两个压缩文件,一个是它的根级别,另一个是它的子文件夹

我的另一个要求是构建文件不知道项目的数量,所以我不能仅仅创建一个ItemGroup并列举我想要压缩的项目


在NAnt中,通过foreach任务可以轻松完成此任务,但如何在MSBuild中实现此任务,最好不要求助于自定义任务?

这很可能是因为本机.Net framework zip功能无法处理嵌套文件夹,仅文件-如果您正在使用的任务使用此功能,则您将运气不佳


另外,您对
ZipSource Include=“\OutDir\**.*”
的语法有点错误,请尝试使用
我想出了一个解决方法-结合使用MSBuild扩展包的FileUnder任务来枚举我要压缩的ProjectX文件夹,以及调用7Zip的Exec任务。代码是:

<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" />


因此,现在每个zip文件都是以其内容来自的文件夹(以及配置和版本控制详细信息)命名的,因此我的输出文件夹中有名为ProjectA-Debug-0.1.2.345.zip等的文件。

不幸的是,MSBuild扩展包中的zip任务与.NET 4不兼容(正在编写替换文件,但目前还不可用)。