I'm creating a Windows Installer (.msi) files by Visual Studio Setup Project. When run .msi file, if target folder already existed and had some files and subfolders then how can i delete them before install my application ? I have already searched but not found solution.

1

There are 1 answers

0
PhilDW On

For an upgrade this should help:

https://www.red-gate.com/simple-talk/dotnet/visual-studio/updates-to-setup-projects/?_ga=2.123102924.696294303.1504290215-1234024276.1504290215

Basically update the setup project's version, accept changes, set RemovePreviousVersions to true when building your upgrade MSI. In addition (not in the article) you must increment the file versions of binaries that are being upgraded. This will do an uninstall of the older product as it installs the new version.

The post doesn't say where the temp files are, but if they are data files or temp files the app shouldn't be creating them in (say) the Program Files folder because it's not the recommended place (there are well defined folders for temp files, such as the Temp Folder), and it requires elevation to write/update files in Program Files so the app is therefore limited to admin users.

Uninstalls don't remove files created by the app (you wouldn't want an uninstall of Word to remove all your doc files) so it might be easier for the app to either not create them there in the first place, or remove them when it first starts up. The normal code solution for uninstalls would be an uninstall custom action in your older product that removes them, but if that old version is already shipped then it's too late.

Also, in a fresh install (even if it's an upgrade) the user could choose to install to another location, if you show the browse dialog to choose the Application Folder, and that means that the files are left in some orphaned Program Files folder, for example.