Skip to content

Instantly share code, notes, and snippets.

@Infarh
Created April 14, 2024 21:01
Show Gist options
  • Save Infarh/88ec380fe976dd7a4a8b84712333da9d to your computer and use it in GitHub Desktop.
Save Infarh/88ec380fe976dd7a4a8b84712333da9d to your computer and use it in GitHub Desktop.
ProjectHack
<Project Sdk="Microsoft.NET.Sdk">
<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>
<Target Name="ZipOutput" AfterTargets="Build">
<ZipDir
ZipFileName="$(OutDir)../MyZipFileName.zip"
DirectoryName="$(OutDir)"
/>
<Message Text="Zipped: $(OutDir)" Importance="high"/>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment