Skip to content

Instantly share code, notes, and snippets.

@brianpursley
Created March 9, 2017 15:08
Show Gist options
  • Save brianpursley/671b1909e2359d2a0ab1ba004f7e5ea7 to your computer and use it in GitHub Desktop.
Save brianpursley/671b1909e2359d2a0ab1ba004f7e5ea7 to your computer and use it in GitHub Desktop.
An example Visual Studio pubxml file to zip the output when publishing an ASP.NET web application to file system
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\Publish\SimpleExample</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
<Target Name="ZipPublishOutput" AfterTargets="GatherAllFilesToPublish">
<Exec Command='powershell -nologo -noprofile -command "compress-archive -force -path $(WPPAllFilesInSingleFolder)\* -destinationpath $(publishUrl).zip"' />
</Target>
</Project>
@nicholasdgoodman
Copy link

For anyone using VS 2019 or later, you can also leverage the <ZipDirectory> task:

  <Target Name="ZipPublishOutput" AfterTargets="FileSystemPublish">
    <ZipDirectory SourceDirectory="$(publishUrl)" DestinationFile="$(publishUrl)\..\$(MSBuildProjectName).zip" />
    <RemoveDir Directories="$(publishUrl)" />
  </Target>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment