- | rssFeed | My book on MSBuild and Team Build | Archives and Categories Friday, May 09, 2014

How to download a site using msdeploy.exe

Recently I encountered a customer asking if it’s possible to download a site using msdeploy.exe. This is pretty easy using msdeploy.exe. I’ll demonstrate this with Microsoft Azure Web Sites but you can use this with any hosting provider that supports Web Deploy (aka MSDeploy).

To perform a sync with msdeploy.exe the structure of the command that we need to execute is as follows.

msdeploy.exe –verb:sync –source:<fill-in-details> –dest:<fill-in-details>

For the source property we will use the remote Azure Web Site, and for the dest property we will write to a folder on the local file system. You can get the Web Deploy publishing settings in the Azure Web Site by clicking on the Download the publish profile link in the Configure page.

image

This will download an XML file that has all the publish settings you’ll need. For example below is a publish settings file for my demo site.

<publishData>
  <publishProfile profileName="sayeddemo2 - Web Deploy" publishMethod="MSDeploy" 
                  publishUrl="waws-prod-bay-001.publish.azurewebsites.windows.net:443" 
                  msdeploySite="sayeddemo2" 
                  userName="$sayeddemo2" 
                  userPWD="*** removed ***" 
                  destinationAppUrl="http://sayeddemo2.azurewebsites.net" 
                  SQLServerDBConnectionString="" mySQLDBConnectionString="" hostingProviderForumLink="" 
                  controlPanelLink="http://windows.azure.com">
    <databases/>
  </publishProfile>
  <publishProfile profileName="sayeddemo2 - FTP" publishMethod="FTP" 
                  publishUrl="ftp://waws-prod-bay-001.ftp.azurewebsites.windows.net/site/wwwroot" ftpPassiveMode="True" 
                  userName="sayeddemo2\$sayeddemo2" userPWD="*** removed ***" 
                  destinationAppUrl="http://sayeddemo2.azurewebsites.net" SQLServerDBConnectionString="" 
                  mySQLDBConnectionString="" hostingProviderForumLink="" 
                  controlPanelLink="http://windows.azure.com">
    <databases/>
  </publishProfile>
</publishData>

The publish settings file provided by Azure Web Sites has two profiles; an MSDeploy profile and an FTP profile. We can ignore the FTP profile and just use the MSDeploy one. The relevant settings from the profile that we will use are the following values.

We will use the contentPath MSDeploy provider to download the files. On the source parameter we will need to include the relevant details of the remote machine. The full command to execute is below. I’ll break it down a bit after the snippet.

"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" 
    -verb:sync 
    -source:contentPath=sayeddemo2,
        ComputerName="https://waws-prod-bay-001.publish.azurewebsites.windows.net/msdeploy.axd?site=sayeddemo2",
        UserName=$sayeddemo2,Password=***removed***,AuthType='Basic'  
    -dest:contentPath=c:\temp\pubfromazure -disablerule:BackupRule

The important parts of the command above are how the remote settings are passed to the source provider. On the dest side I’ve provided the location where the files should be downloaded to.

 

Sayed Ibrahim Hashimi | http://msbuildbook.com/ | @SayedIHashimi

Friday, May 09, 2014 12:02:02 AM (GMT Daylight Time, UTC+01:00)  #     |