Visual Studio 2019: "delete existing files" option in publish profile disappeared

Viewed 3001

I've just updated my copy of Visual Studio to version 16.10, and something weird happened: when publishing a project, the "delete existing files" option is not editable anymore. You can see it but when opening the edit dialog there is no checkbox to edit it.

Here's a screenshot for clarification: enter image description here

Is this a bug, or is it intended? Is there an alternative way to set that option, or is it just not supported anymore?

4 Answers

I initially tried adding <DeleteExistingFiles>true</DeleteExistingFiles> to the pubxml file (under the Properties folder in VS). Unfortunately, this only update the Publish dialog but had no apparent effect on the publishing process.

For my workaround, I opted to add this to build event: del /S /Q $(TargetDir)publish. It clears out my publish directory on each build - you'll have to alter "$(TargetDir)publish" to fit your needs. The workaround is slight overkill, but arguably a better choice since there is less chance of the published files being picked up after a recent change/build.

enter image description here

I've just updated Visual Studio to version 16.11 and it seems they fixed it, the option is back in the settings menu:

enter image description here

Open .pubxml file in a text editor (mine was in Properties\PublishProfiles) and update/add the key DeleteExistingFiles to True.

I think regarding @Phil's answer, the 2 actions are doing different things.

1. DeleteExistingFiles

This will delete existing files on the web server when you actually deploy. I don't see any documentation about this setting from Microsoft which is frustrating. This same feature is available when you publish your application to a Web Deploy Package and use the Import feature in IIS to import the application. You will get a prompt like this: enter image description here

This is the same as DeleteExistingFiles in a publish profile.

2. Publish directory

Deleting the publish directory is a different thing. The publish directory is a working directory of the msbuild /t:Publish or msbuild /t:Package commands. Basically what is in the publish directory is what ends up in the ZIP file used for a web deploy package or a publish profile. You can get issues during publish process with incorrect files in the publish directory. For example, https://github.com/scottksmith95/LINQKit/issues/157. Unfortunately there is no way to delete or clean the publish directory with the existing msbuild or dotnet cli commands: https://github.com/dotnet/sdk/issues/5972.

Fun times. So @Phil's del command is what we are left with.

Related