在MSBuild中,我包含的.xml文件包含:
<Target Name="Zip">
<ItemGroup>
<WorkingDirect Include="$(DeployDirectory)$(PackagePrefix)\$(PackageFolder)"/>
</ItemGroup>
<CreateItem Include="$(DeployDirectory)$(PackagePrefix)\$(PackageFolder)\*.*" >
<Output ItemName="ZipFiles" TaskParameter="Include"/>
</CreateItem>
<Message Text="@(WorkingDirect)" Importance="High" />
<Zip ZipFileName="YourZipFile.zip" WorkingDirectory="@(WorkingDirect)" Files="@(ZipFiles)" />
</Target>
在论坛中,据说为了压缩我需要在上面添加的部署包。但我收到以下错误:
[15:54:50][Zip] C:\TeamCity\buildAgent\work\c14fc97466c6d06e****cmss.xml(148, 44): error MSB4064: The "WorkingDirectory" parameter is not supported by the "Zip" task. Verify the parameter exists on the task, and it is a settable public instance property.
[15:54:50][Zip] C:\TeamCity\buildAgent\work\c14fc97466c6d06e****cmss.xml(148, 9): error MSB4063: The "Zip" task could not be initialized with its input parameters.
[15:54:50][Step 1/1] Process exited with code 1
但是在build.log中,似乎参数设置正确:
[Zip] C:\DeployPackages\**\20150725_155148
我一直在寻找很长的时间,请有人帮帮我???
提前致谢...
答案 0 :(得分:0)
一切都很顺利;非常感谢我的老板:)他给我发了正确用法的链接。对于任何从部署软件包创建zip文件的人:(http://www.msbuildextensionpack.com/help/3.5.14.0/index.html)
<Project ToolsVersion="3.5" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
<TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
</PropertyGroup>
<Import Project="$(TPath)"/>
<Target Name="Default" DependsOnTargets="Sample1;Sample2"/>
<Target Name="Sample1">
<ItemGroup>
<!-- Set the collection of files to Zip-->
<FilesToZip Include="C:\Patches\**\*"/>
</ItemGroup>
<!-- Create a zip file based on the FilesToZip collection -->
<MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" CompressFiles="@(FilesToZip)" ZipFileName="C:\newZipByFile.zip"/>
<MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" Password="apassword" CompressionLevel="BestCompression" RemoveRoot="C:\Patches" CompressFiles="@(FilesToZip)" ZipFileName="C:\newZipByFileBestCompression.zip"/>
<!-- Create a zip file based on a Path -->
<MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" CompressPath="C:\Patches" ZipFileName="C:\newZipByPath.zip"/>
<!-- Extract a zip file-->
<MSBuild.ExtensionPack.Compression.Zip TaskAction="Extract" ExtractPath="C:\aaa11\1" ZipFileName="C:\newZipByFile.zip"/>
<MSBuild.ExtensionPack.Compression.Zip TaskAction="Extract" ExtractPath="C:\aaa11\2" ZipFileName="C:\newZipByPath.zip"/>
<MSBuild.ExtensionPack.Compression.Zip TaskAction="Extract" Password="apassword" ExtractPath="C:\aaa11\3" ZipFileName="C:\newZipByFileBestCompression.zip"/>
</Target>
<Target Name="Sample2">
<PropertyGroup>
<SourceDirectory>MotorData\</SourceDirectory>
</PropertyGroup>
<ItemGroup>
<Files Include="$(SourceDirectory)*" Exclude="$(SourceDirectory).XYZ\**\*">
<Group>Common</Group>
</Files>
<Files Include="$(SourceDirectory)Cars\*" Exclude="$(SourceDirectory)Cars\.XYZ\**\*">
<Group>Cars</Group>
</Files>
<Files Include="$(SourceDirectory)Trucks\*" Exclude="$(SourceDirectory)Trucks\.XYZ\**\*">
<Group>Trucks</Group>
</Files>
</ItemGroup>
<!-- Create the output folder -->
<ItemGroup>
<OutputDirectory Include="output\"/>
</ItemGroup>
<MakeDir Directories="@(OutputDirectory)"/>
<PropertyGroup>
<WorkingDir>%(OutputDirectory.Fullpath)</WorkingDir>
</PropertyGroup>
<!-- Zip files based on the group they belong to -->
<MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" CompressFiles="@(Files)" ZipFileName="$(WorkingDir)%(Files.Group).zip"/>
</Target>
</Project>