Msbuild 压缩内容而不保留文件夹结构

Msbuild 压缩内容而不保留文件夹结构,msbuild,Msbuild,我正在编写自定义msbuild脚本。 其中一个目标应该压缩构建输出。 为了便于示例,让我们假设以下是输出路径 C -Folder -------bin ----------Debug 我有以下MsBuild目标 <Target Name="ZipFiles"> <ItemGroup> <Binaries Include="$(MSBuildProjectDirectory)\Folder\bin\Debug\**" /&

我正在编写自定义msbuild脚本。 其中一个目标应该压缩构建输出。 为了便于示例,让我们假设以下是输出路径

C
-Folder
-------bin
----------Debug
我有以下MsBuild目标

    <Target Name="ZipFiles">
        <ItemGroup>
          <Binaries Include="$(MSBuildProjectDirectory)\Folder\bin\Debug\**" />
        </ItemGroup>   

        <MakeDir Directories="$(MSBuildProjectDirectory)\Build\Output"
                 Condition="!Exists('$(MSBuildProjectDirectory)\Build\Output')" />

        <Zip Files="@(Binaries)"
             WorkingDirectory="$(MSBuildProjectDirectory)\Build\Output\"
             ZipFileName="$(MSBuildProjectDirectory)\Build\Output\MyItems.zip"
             ZipLevel="9" />
    </Target>
我想要实现的是在.zip文件中包含调试内容,而不保留文件夹结构,直到调试结束。 因此,我希望以.zip文件结束,其中包含以下内容

    MyItem.zip
    ----------Content Folders (for example Resources)
    -------------------------Content Files
    ----------Files
有什么优雅的方法吗

我不希望使用任何自定义PowerShell脚本,如果可能,请使用MsBuild+社区任务提供的脚本。

请参阅社区任务的文档:

/// <summary>
/// Gets or sets the working directory for the zip file.
/// </summary>
/// <value>The working directory.</value>
/// <remarks>
/// The working directory is the base of the zip file.  
/// All files will be made relative from the working directory.
/// </remarks>
public string WorkingDirectory { get; set; }
因此,如果您指定workingdirectory,它将用于确定内容的“起点”,在您的情况下,应该是


$MSBuildProjectDirectory\Folder\bin\Debug

来自文档:工作目录是zip文件的基础。所有文件都将与工作目录相对。听起来像是你的问题?请尝试保留工作目录,或将其设置为$MSBuildProjectDirectory\Folder\bin\Debug@stijn就是这样!谢谢你,工作很有魅力!请你把它作为答案贴出来,这样我就可以标记它了。
/// <summary>
/// Gets or sets the working directory for the zip file.
/// </summary>
/// <value>The working directory.</value>
/// <remarks>
/// The working directory is the base of the zip file.  
/// All files will be made relative from the working directory.
/// </remarks>
public string WorkingDirectory { get; set; }