Created
September 22, 2017 09:42
-
-
Save codepunkt/9bada316294da3f64b13427f961fcd00 to your computer and use it in GitHub Desktop.
Zip file in msbuild build event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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