Skip to content

Instantly share code, notes, and snippets.

@codepunkt
Created September 22, 2017 09:42
Show Gist options
  • Save codepunkt/9bada316294da3f64b13427f961fcd00 to your computer and use it in GitHub Desktop.
Save codepunkt/9bada316294da3f64b13427f961fcd00 to your computer and use it in GitHub Desktop.
Zip file in msbuild build event
<Target Name="Build">
<ZipDir
ZipFileName="MyZipFileName.zip"
DirectoryName="MyDirectory"
/>
</Target>
<UsingTask TaskName="ZipDir" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<ZipFileName ParameterType="System.String" Required="true" />
<DirectoryName ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.IO.Compression.FileSystem" />
<Using Namespace="System.IO.Compression" />
<Code Type="Fragment" Language="cs"><![CDATA[
try
{
Log.LogMessage(string.Format("Zipping Directory {0} to {1}", DirectoryName, ZipFileName));
ZipFile.CreateFromDirectory( DirectoryName, ZipFileName );
return true;
}
catch(Exception ex)
{
Log.LogErrorFromException(ex);
return false;
}
]]></Code>
</Task>
</UsingTask>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment