How To Automatically Zip ASP.NET File System Publish Output

If you use the File System publish method to publish an ASP.NET web application, you will get the output in a folder you choose. But what if you want the output in a zip compressed folder instead? I got tired of manually zipping the output folder, so I added a step to the end of the publish process to automatically compress the output folder into a zip file.

I did this by adding a custom target to my project’s pubxml file. The custom target executes the compress-archive powershell command (see highlighted section below):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="">
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
  <Target Name="ZipPublishOutput" AfterTargets="GatherAllFilesToPublish">
    <Exec Command='powershell -nologo -noprofile -command "compress-archive -force -path $(WPPAllFilesInSingleFolder)\* -destinationpath $(publishUrl).zip"' />


Leave a Reply

Your email address will not be published. Required fields are marked *