'Web Deploy Tip: Deploying a site to a different directory on the destination'

Recently, a customer contacted me, asking me how they can deploy a site to a different directory on source. For example, a site is under c:inetpubmysite on the source computer, and they want to deploy to c:newdir on the destination.

Here’s how you do it:

msdeploy.exe -verb:sync -source:apphostconfig="Default Web Site" -dest:package=c:tempmypackage.zip -setparam:type=DestinationVirtualDirectory,scope="Default Web Site",value="c:newdir"

Let’s take this apart:

  • -verb:sync. This tells Web Deploy to do a sync operation (vs. dump or getParameters).

  • -source:appHostConfig. This tells Web Deploy to use the apphostconfig provider, which is capable of moving, among other things, file system contents, setting ACLs on file system objects, etc. basically most components of a website.

  • -setParam: Now you may be wondering … why am I setting a parameter if I haven’t declared it first using –declareParam? Under the covers, Web Deploy auto-parameterizes some providers. You can read more about it here: http://technet.microsoft.com/en-us/library/dd569084(WS.10).aspx.

    • The specific setting we want to parameterize is DestinationVirtualDirectory. I specify the destination path as a value for this parameter.

I am syncing to a package, but you could just as easily sync to a remote computer directly.