WebDeploy/MSDeploy Quick TIP: Change IIS Site/APP Physical Path with MSDeploy

I’ve now seen several questions on StackOverflow about changing the physical path of an IIS site/app using MSDeploy.   So I figured this may be helpful for others.

I believe MSDeploy can set the physical path using the appHostConfig provider but it didn’t look straight forward.  After thinking through this further I decided the runCommand provider would probably be more simple/flexible for most use cases.  Here is a manifest snippet you could use (or you could also extend WebDeploy via MSBuild in a similar way – see http://www.dotnetcatch.com/2016/05/19/extending-the-webdeploy-manifest/):

<runcommand path="%windir%\system32\inetsrv\appcmd set app /app.name:&quot;Default Web Site/app12&quot; /&#91;path='/'&#93;.physicalPath:C:\temp\app12" waitInterval="5000"/>

Here we are calling appcmd which is provided with IIS to configure sites/apps via the commandline.  And here is the result in the context of an actual MSDeploy deployment:

Info: Updating runCommand (%windir%\system32\inetsrv\appcmd set app /app.name:"Default Web Site/app12" /[path='/'].physicalPath:C:\temp\app12).
Info: APP object "Default Web Site/app12" changed

Warning: The process 'C:\Windows\system32\cmd.exe' (command line '') exited with code '0x0'.
Total changes: 1 (0 added, 0 deleted, 1 updated, 0 parameters changed, 0 bytes copied)

The path value may change depending on your site/app setup.  You can use the following command to find the appropriate path:

>%windir%\system32\inetsrv\appcmd list app /app.name:"Default Web Site/app12" /config
<application path="/app12" applicationPool="DefaultAppPool">
  <virtualDirectoryDefaults />
  <virtualDirectory path="/" physicalPath="C:\temp\app12" />
</application>

Hope this helps others.  If so, please let me know in the comments below or on Twitter (@chief7).

Leave a Reply