This post describes how to deploy a ASP.net MVC web application with msdeploy, while skipping the overwriting of the root web.config file. Sounds easy, what could possiblie go wrong? Well, msdeploy can be a real pain to try and figure out, but at least it’s the sort of thing you write once and keep in the back pocket.
This example deploys from an existing ‘last build’ staging area to a ‘beta’ staging area but doesn’t copy across the configuration or error files.
1 2
"c:\Program Files\IIS\Microsoft Web Deploy V2\msdeploy.exe" -verb:sync -source:iisApp="LastBuild" -dest:iisApp="Beta" -skip:objectName=dirPath,absolutePath="elmah" -skip:objectName=filePath,absolutePath="^((?!Views).)*web\.config$" -skip:objectName=filePath,absolutePath="settings-override.xml" pause
The tricky bit that this command is handling is that MVC doesn’t just have the one web.config file. Each view folder also contains a web.config file used by the view engine, so simply ignoring files name web.config will deploy a broken web application. The example above works because msdeploy allows regular expressions, this regular expression skips over the web.config in the root directory but still copies over the others that are in ‘Views’ folders.
You can see how the regular expression works at this handy site.