This can be done by manually invoking msdeploy - just add the following parameter:
-skip:Directory=\\App_Data
See Website Deployment Options . The path is a regular expression, so it is quite flexible.
If you deploy using the VS ProjectName.deploy.cmd script you created, you can also pass this parameter in the _MsDeployAdditionalFlags environment variable (when you run the script).
This is the best I have come up with for our needs (we have the same situation as you). I did not try to integrate it with the VS Publish button, since we are deploying from the command line.
EDIT:
I found out something about MSDeploy since I posted this answer, so I decided to update it now.
First of all, the skip rule above skips any operations on the matching path (App_Data). If more detailed control is required, more detailed syntax is available. For example, to skip only deleted files (to save additional files on the target server, but add new ones and update existing ones):
-skip:skipaction='Delete',objectname='filePath',absolutepath='\\App_Data\\.*' -skip:skipaction='Delete',objectname='dirPath',absolutepath='\\App_Data\\.*'
This skips the deletion of all files and all subfolders (with all their contents) in App_Data, but does not prevent the addition and updating.
Another useful thing: skipping rules can be defined in the project file ( .csproj ) so that they are automatically included in the .deploy.cmd script generated with the package. This makes it unnecessary to pass them to the script through _MsDeployAdditionalFlags.
The above skip rule will be added if the following is included in the csproj file:
<PropertyGroup> <OnBeforePackageUsingManifest>AddCustomSkipRules</OnBeforePackageUsingManifest> </PropertyGroup> <Target Name="AddCustomSkipRules"> <ItemGroup> <MsDeploySkipRules Include="SkipDeleteAppData"> <SkipAction>Delete</SkipAction> <ObjectName>filePath</ObjectName> <AbsolutePath>$(_Escaped_PackageTempDir)\\App_Data\\.*</AbsolutePath> <XPath> </XPath> </MsDeploySkipRules> <MsDeploySkipRules Include="SkipDeleteAppData"> <SkipAction>Delete</SkipAction> <ObjectName>dirPath</ObjectName> <AbsolutePath>$(_Escaped_PackageTempDir)\\App_Data\\.*</AbsolutePath> <XPath> </XPath> </MsDeploySkipRules> </ItemGroup> </Target>
(the names AddCustomSkipRules and SkipDeleteAppData are completely arbitrary; it is assumed that $(_Escaped_PackageTempDir) may be required, but in practice I always saw how it evaluates an empty string)
See Web Deployment: Configuring Deployment Pack and How to Set MSDeploy Settings in a .csproj File for more information.
One caveat: this only adds these rules to the .deploy.cmd script, so it is useless if you want to use the IIS graphical manager to deploy the package since it does not use this script (the same probably goes for deployment from VS, but I did not check )