Dotnet publish and delete existing files from App Service using the Visual Studio IDE. Remove additional files at the destination is the feature available in Visual Studio.
Remove additional files at destination
When you are ready to publish your application in Web App, you can delete the existing files at the destination. This helps in clearing the unused files from your last deployment.
Let’s take an example first and then we will look at enabling this option in Visual Studio. In your first deployment, you had a class file with the name UserRepository.cs
. When you build your project, a UserRepository.dll
is generated which is deployed to your App Service.
You realized that you do not need UserRepository.cs file anymore and you deleted it from the project files. With this action, the DLL file will not be generated. If you do not switch on the option to remove additional files at the destination, then on your next deployment, the UserRepository.dll will still be present in the App Service even though it is not used.
To remove the unused file, we just turn on the option to remove additional files at the destination.
How to Turn on Remove additional files at destination in Visual Studio?
Go to your publish profile in Visual Studio. I am working on Visual Studio 2022, therefore my UI might be different if you are using a lower version of Visual Studio. You might have the same option but with a different descriptive text.
Click on Show all settings
.

Under File Publish Options
, turn on the Remove additional files at destination. Click on Save
.

Conclusion
On your next deployment, all the unused or additional files will be removed from the destination for dotnet publish in Visual Studio.
Leave a Reply