Title: How can I make the msi overwrite old files?
Tags: c#;.net;iis;installation
Question: I have a standard Visual Studio (2008) application setup project, which generates an msi containing a few files. I noticed however that:
1) When the msi installs and some of the files already exist, it simply silently ignores these files. This is the behaviour that I don't want, because of obvious reasons.
2) When I uninstall the msi, it doesn't delete my main dll file.
How can I fix these two things? Together they make it impossible to automatically upgrade my software.

Here is the accepted answer: I had the exact same problem and eventually gave up. Getting it to work is a horrible, complicated process involving lots of GUIDs. You'll feel very dirty afterward (assuming you ever get it to work).
My advice is to switch to Inno Setup which is much more suited to people like you and me.
Leave .msi to people who do "corporate rollouts" instead of "installs".
Comment for this answer: Heh, that what I was worried about. I already wasted 2 weeks on these msis. Eh, just another thing M$ f..ed up completely.

Here is another answer: Insofar as not removing all the files, check the reference count under
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs]
If you've used MSIZAP aka the "Windows Installer Cleanup Utility" you've basically put your machine into an unknown state and you'll need to manually remove everything from the registry (in my company we have a utility that removes all known registry entries from the last 10 releases of the product, basically consisting of a 1000 line .reg file and some other tools) before you can reliably test your setup again.
See http://robmensching.com/blog/posts/2009/3/6/More-on-Haacks-Troubleshooting-Windows-MSI-Installers for a bit more information about what happens when you get your machine into an "unsupported state" and how you'll need to manually clean up things or reformat before continuing.
We came across this problem as Installshield automatically defaults to setting components as shared components, so we'd end up with weird reference counting bugs, files left behind, etc, etc. A really ugly solution.
For your upgrades, try doing major upgrades rather than minor upgrades (patches) as this is a lot easier to get your head around when you're first getting into Windows Installer. But first, you'll need to get your app uninstalling correctly, then you can move onto the upgrade. If it won't uninstall properly, it won't upgrade properly.
Comment for this answer: Either that or use an installer that doesn't need all that.

Here is another answer: I had a similar looking issue when I was testing overwriting existing files with an MSI - existing older files were not being replaced with newer files in the MSI.
What it was that my newer files which did not overwrite the existing were versioned files (they were DLLs), and the file version numbers had not changed, even though the modified dates were later.  As soon as I changed the file version number on the newer files to be a higher version than the existing files, then the existing files got overwritten by the msi.
And then there were other files, like .manifest and .vsto, which were generated by Visual Studio, and these files are unversioned and normally follow installer versioning rules.  These all actually relate to a DLL file, and providing a CompanionFile attribute referring to that DLL for each of the .manifest, .vsto, etc. files did the trick.

Here is another answer: Have you incremented the version number in your setup project? Incrementing the version number will also ask you to create a new product id. You should confirm this question with yes.

Here is another answer: Another option is to uninstall the current application programitally and install the new msi
however this will require a custom winforms application

Here is another answer: Another option is to include the version number in the application's install folder.
Set Application folder's default location to something like:
[ProgramFilesFolder]\\[ProductName]\\[ProductVersion]
Also set the Setup project's RemovePreviousVersions property to true.
This should delete the old version's folder and create a fresh folder for the new version.
Remember to change the Setup project's version property every time you do a new release.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 6, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2009:00:03/23/09', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<c#><.net><iis><installation>', 'Title': 'How can I make the msi overwrite old files?', 'ViewCount': 6230, 'id': 674233, 'user_AboutMe': '<p>Software Engineer at Google</p>\n', 'user_AccountId': 3698.0, 'user_DisplayName': 'Grzenio', 'user_Reputation': 35089.0, 'user_Views': 1909.0, 'user_id': 5363.0}}