Publish Profile App_Data recursive inclusion and deletion behavior
0 reputation · 28 Nov 2022, 09:43 UTC
0 reputation · 28 Nov 2022, 09:43 UTC
Visual Studio publish profiles provide options to manage the target directory state and specific folder inclusions. When the Delete all existing files prior to publish option is enabled, the MSBuild process is intended to purge the destination before copying new assets.
Concurrent with this, the Include all files in the App_Data folder setting is used to ensure application data is migrated to the remote server. However, there is uncertainty regarding how these two settings interact when the App_Data folder contains a nested directory structure.
It is unclear if the deletion policy recursively removes all sub-directories within App_Data before the inclusion policy triggers a recursive copy of the same nested files. Current logs at the Information level do not explicitly distinguish between files skipped by the include set and files removed by the purge operation.
Delete all existing files setting recursively purge nested sub-folders within App_Data?Include all files in the App_Data folder operation recursive for all nested levels, or limited to the top-level directory?33275 reputation · 28 Nov 2022, 17:51 UTC
When you enable Delete all existing files prior to publish, the MSDeploy engine performs a full, recursive delete of the target folder. That includes every sub‑directory and file under App_Data. After the purge, the Include all files in the App_Data folder option copies the entire App_Data tree back to the destination, again recursively. In short:
<PropertyGroup>
<MSDeployLogLevel>Verbose</MSDeployLogLevel>
</PropertyGroup>
dotnet publish -c Release -o publish or via VS). The log will contain lines like:
Delete: /site/wwwroot/App_Data/SubFolder
Delete: /site/wwwroot/App_Data/SubFolder/file.txt
Copy: /site/wwwroot/App_Data/SubFolder/file.txt
App_Data subfolders and files exist and match the source.
App_Data should be added, while existing ones are preserved.
MSDeploy parameters, such as Skip or ExcludeFromPackageFiles, can prevent certain subfolders from being deleted or copied.
Do you have any custom MSDeploy parameters or publish scripts that might modify the delete or include steps? That could change the outcome described above.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.