Make MSDeploy (Visual Studio) not delete the App_Data folder, but delete everything else

I use the Visual Studio Publish button to deploy my site and want the server to have a different App_Data folder. There is a checkbox for Leave extra files on destination (do not delete) that prevents my App_Data folder from being deleted, but then it eventually accumulates a lot of rudimentary files as the website changes.

Is there a way to make it exclusive only to App_Data when it removes everything?

+55
iis deployment msdeploy
Nov 27 '10 at 0:35
source share
7 answers

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 )

+91
Apr 14 '11 at 6:24
source share
— -

You looked at Web Package / Publish in the project settings because you can say that it excludes files in the App_Data folder.

+1
Oct 20 2018-11-18T00:
source share

In my experience, MsDeploySkipRules only execute when deployed from the command line.

If you are publishing from Visual Studio to Azure (or using another Web Deploy method), you can set the following when publishing.

  • Delete additional files at destination
  • Exclude files from the App_Data folder li>

When “Delete additional files at destination” is checked, it will compare between the files and folders that you are deploying and those on the server.

Be careful, you may run into problems if you have custom content, for example. Downloads. But this could be circumvented by saving these folders elsewhere, for example. S3 / Azure Storage.

Web Publishing Profile

0
Feb 07 '18 at 13:22
source share

This is not ideal, since you can copy many files by doing this (I do not), but here is my solution for backing up the folder. Adapted to move a folder to the folder from which it will be published, during the publishing process. Put this in your pubxml file:

 <Project> ... <Target Name="PreserveSelectedFolder" AfterTargets="GatherAllFilesToPublish"> <ItemGroup> <SITEDIR Include="$(publishUrl)\App_Data\**\*.*" /> </ItemGroup> <Copy SourceFiles="@(SITEDIR)" DestinationFolder="$(ProjectDir)\obj\$(Configuration)\Package\PackageTmp\%(RecursiveDir)"></Copy> </Target> </Project> 

And if you just want to make any number of specific known files, make one block instance for each file:

 <Target Name="PreserveSelectedFiles" AfterTargets="GatherAllFilesToPublish" > <Copy SourceFiles="$(publishUrl)\MYFILENAME.EXT" DestinationFolder="$(ProjectDir)\obj\$(Configuration)\Package\PackageTmp\" Condition="Exists('$(publishUrl)\MYFILENAME.EXT')"></Copy> </Target> 
0
Aug 29 '18 at 19:46
source share

For main asp.net web applications, use MsDeploySkipRules in csproj.

 <ItemGroup> <MsDeploySkipRules Include="CustomSkipFile"> <ObjectName>filePath</ObjectName> <AbsolutePath><dir_name>\\app_data</AbsolutePath> </MsDeploySkipRules> <MsDeploySkipRules Include="CustomSkipFile"> <ObjectName>dirPath</ObjectName> <AbsolutePath><dir_name>\\app_data</AbsolutePath> </MsDeploySkipRules> </ItemGroup> 

Replace <dir_name> your root folder

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-2.1#exclude-files

0
Oct 26 '18 at 11:46
source share

From Powershell, if you want to use msdeploy.exe or myproj.deploy.cmd ( Deploy Web Packs ) created when publishing to Web Deploy to skip deleting the App_Data folder and avoid

 All arguments must begin with "-" 

errors, you must enclose the skip directive in triple quotes, for example:

 myproj.deploy.cmd /y /u:myusername /p:mypass """-skip:Directory=\\App_Data""" 
0
Nov 25 '18 at 15:33
source share

Put this in your pubxml file:

 <ExcludeApp_Data>True</ExcludeApp_Data> 
-one
Sep 26 '18 at 4:42
source share



All Articles