Skip to content

Commit a66f426

Browse files
authored
[master] Implemented option to preserve the destination folder for File System publishes when Delete existing files option is selected (#15494)
* [master] Implemented option to preserve the destination folder for File System publishes when Delete existing files option is selected Currently when the File System publish goes to delete the existing files, it also deletes and recreates the target folder. This can have unwarranted side effects, one such being that ACL's on the target folder are removed, and reset based on how the new folder is created (typically just inheriting permissions from the next parent folder). When publishing directly to a web server in this way, any folder permissions that were directly on the folder are lost, and can cause issues for developers who are unaware of this behavior and are attempting to configure permissions for IIS and the web server (an already tricky task). I'm sure there are other scenarios where deleting the target folder is not desired. By providing an opt-in option to preserve the destination folder, this issue can be bypassed, yet users can still take advantage of the cleanup to remove older website files that may be outdated or defunct inside of the destination. This option should not affect older publish profiles if they do not have this setting, as I'm hopeful it would default to false in such cases. For the UI in Visual Studio for configuration, a new checkbox option could be introduced below the "Delete existing files" checkbox. This new option could say "Preserve destination folder" and would be unchecked and disabled until "Delete existing files" is checked, then giving users the option to check it. * Corrected logic on PreserveDestinationFolder conditional Based on the MSBuild Conditions documentation, this should have been != 'true' in order to truly support backwards compatibility. https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditions?view=vs-2019 Excerpt: In MSBuild project files, there's no true Boolean type. Boolean data is represented in properties that might be empty or set to any value. Therefore, '$(Prop)' == 'true' means "if Prop is true," but '$(Prop)' != 'false' means "if Prop is true or unset or set to something else."
1 parent 8ad5e3a commit a66f426

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/WebSdk/Publish/Targets/PublishTargets/Microsoft.NET.Sdk.Publish.FileSystem.targets

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ Copyright (C) Microsoft Corporation. All rights reserved.
6666

6767
<RemoveDir
6868
Directories="$(PublishUrl)"
69-
Condition="'$(DeleteExistingFiles)' == 'true' And Exists('$(PublishUrl)')" />
69+
Condition="'$(DeleteExistingFiles)' == 'true' And '$(PreserveDestinationFolder)' != 'true' And Exists('$(PublishUrl)')" />
7070

7171
<MakeDir
7272
Directories="$(PublishUrl)"
73-
Condition="'$(DeleteExistingFiles)' == 'true' And !Exists('$(PublishUrl)')"/>
73+
Condition="'$(DeleteExistingFiles)' == 'true' And '$(PreserveDestinationFolder)' != 'true' And !Exists('$(PublishUrl)')"/>
7474
</Target>
7575

7676
<!--

0 commit comments

Comments
 (0)