我有一个如下所示的 MSBuild 脚本,它获取类库 Bin\Release\MyLib.dll
并将其压缩到 C:\1.zip
中。
当我打开 zip 文件时,我在父文件夹中看到 MyLib.dll
文件。
但是我希望 ZIP 文件中有一个目录结构,因此该文件将被压缩为 lib\MyLib.dll
我怎样才能做到这一点?
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Target Name="AfterBuild">
<PropertyGroup>
<ReleasePath>bin\Release\</ReleasePath>
</PropertyGroup>
<ItemGroup>
<ReleaseApplicationFiles
Include="$(ReleasePath)\**\*.*"
Exclude="$(ReleasePath)\*vshost.exe*;$(ReleasePath)\*.pdb*" />
</ItemGroup>
<Zip Files="@(ReleaseApplicationFiles)"
WorkingDirectory="$(ReleasePath)"
ZipFileName="c:\1.zip"
ZipLevel="9" />
</Target>
最佳答案
我愿意:
- 创建“lib”文件夹
- 将相关 DLL 复制到“lib”文件夹
- 压缩“lib”文件夹,其中现在包含 DLL。
代码如下:
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Target Name="AfterBuild">
<PropertyGroup>
<ReleasePath>bin\Release\</ReleasePath>
<Zipup>c:\archive\bin</Zipup>
</PropertyGroup>
<ItemGroup>
<ReleaseApplicationFiles Include="$(ReleasePath)\**\*.*" Exclude="$(ReleasePath)\*vshost.exe*;$(ReleasePath)\*.pdb*" />
</ItemGroup>
<Exec Command="mkdir $(Zipup)" IgnoreExitCode="False"/>
<Copy DestinationFolder="$(Zipup)" OverwriteReadOnlyFiles="True" SkipUnchangedFiles="False" SourceFiles="@(ReleaseApplicationFiles)" />
<Zip Files="$(Zipup)"
WorkingDirectory="$(ReleasePath)"
ZipFileName="c:\1.zip"
ZipLevel="9" />
</Target>
关于visual-studio-2010 - MSBuild.Community.Tasks 和 Zip,设置 zip 文件夹结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9077521/