Does Uninstall action run during product upgrade? - visual-studio

I want to add a custom action to my visual studio installer project to delete some files that are created by my app during runtime. These files are dynamically created and not deleted as part of the normal uninstall.
My question is: what happens when you upgrade or update the application by installing a newer version? Does the installer run the Uninstall custom action?
I do have RemovePreviousVersions set to True in the deployment project properties. I'd actually like to delete the files only if it's a true removal not an upgrade.

RemovePreviousVersions will perform an uninstall.
If I understand your question correctly, you have files that are created after the application has been installed and you wish these to be removed when the product is uninstalled and not during upgrades.
I do not have experience with the VS installer types, but look for something that gives you access to the RemoveFile table. https://msdn.microsoft.com/en-us/library/windows/desktop/aa371201(v=vs.85).aspx
If the vs installer doesn't expose the RemoveFile table you may need to look into InstallShield 2016/2017 Pro or Premium. If you are really adventurous then look at WIX.

Related

VS 2008 Setup changed, having two installations in Control Panel

My Visual Studio 2008 setup project is changed so that merge modules for MFC and VC have replaced DLL's that were installed manually in the installation folder. I'm okay with merge modules, but there is a problem. In previous setup user could choose between "Everyone" and "Just me". In new setup this choice has no effect, and installation is always for everyone because of merge modules, which must be installed for everyone. So, if previous installation was "just for me" then new installation does not remove DLL's of previous installation, and in Control Panel there are two installations with the same name.
In setup project of new version ProductCode is changed, UpgradeCode is not, RemovePreviousVersion is set to true, and Version is higher than it was before.
If I exclude merge modules from setup, and install new version "just for me" then all is well. Old files are removed, and there's only one installation in Control Panel. But I would rather not burden users with separate installation of redistributable packages.
How can I in Visual Studio 2008 setup have both merge modules, and instruct setup to remove previous version, even though previous version was "just for me", and new is for "everyone"?
Mаybe better question would be what would you do in my place to resolve this issue?
Windows Installer (handler of MSI files) will not uninstall one product during the installation of another. Also, the same installation is viewed as two different products when installed both per user ("just me") and per machine ("everyone"). It is therefore nothing you can do from .msi to uninstall old per user installation if new is to be installed per machine.
Options are, ordered by preference:
Make bootstrapper installation (.exe) that would seek and uninstall all that needs uninstalling. Bootstrapper is also preferred way to install prerequisites, instead of doing with merge modules.
From .msi you can just detect that something is wrong, and stop the installation. I've done this, but will work on first option as well.
Ignore the problem, say it's by design, and do nothing. It's all in the hands of the user.

WIX UI Installer Project in Visual Studio, Now Mange Updates?

I have a fresh WIX UI Install project in VS which compiles down into an MSI. Everything is working great with it.
It installs/uninstalls the files I want successfully. For example, it drops 3 DLLs into a Program Files folder, installs a Windows Service, and GAC's a DLL.
Now let's say I install on this in a given environment. Then one of our DLLs change and we need to upgrade this install without affecting other files already installed (such as the service) So my thought would be I would need a patch/upgrade MSI that would target that one DLL and just overwrite that particular file.
What is the simplest way to accomplish this? Do I need VS projects essentially for each patch/update MSI? Below is my current 2 WIX related projects (installer + custom action)
For updating just the DLL a patch is recommended. Visual Studio doesn't support patches, but you can try using WiX: http://wix.sourceforge.net/manual-wix2/patch_building.htm
Please note that patches have some restrictions: http://msdn.microsoft.com/en-us/library/aa367850(VS.85).aspx
A MSI which overwrites just one file is a bad mistake because you are not using the Windows Installer update mechanism.
If you want a MSI, it will have to be a major upgrade. A major upgrade will automatically uninstall the old version before installing the current one.

Visual Studio: How to automatically uninstall previous installed version?

I have a simple Web Setup project that reads from a Deployable Project.
Even though I have set the Setup to DetectNewerInstalledVersion to false I always get that annoying alert box that a previous installation exists and I need to go to the Control Panel and find the software to remove it...
Is there a way to add a script in a new new installation Dialog that could say A previous version was found, press NEXT to uninstall it. ?
Older versions are uninstalled automatically if you increase your Product Version and change the Package Code. This needs to be done each time you modify the setup project and build a new package.
If you keep the same version and Product Code, older builds cannot be uninstalled automatically. They are detected by Windows Installer before your new package is actually launched. So you need to uninstall them manually.
In my case I found out that the setup project wasn't part of the configuration manager.
Therefore, it wasn't rebuld on solution rebuilds and setup file with the new version and ProductCode wasn't generated.
The solution is simply to right click on the setup project and click rebuild.
Hope this help to future readers :)
The answer is not to use the Visual Studio setup project that's already integrated. I'm having the exact same problem: it won't remove previous versions even though I up the version, set it to remove previous version, check for previous version and rebuild, I can install but the files aren't updated. There are some good tools for this out there, check out bitrock, inno setup or wix.
Also Visual Studio 2010 was the last version with setup project support. It's not included in 2012.
I struggled with this for a long time but it is very simple.
Go to manage VS Extensions (VS2019) and install 'Microsoft Visual Studio Installer Project' v0.9.9
Right click on your installer project and go to properties. Keep the UpgradeCode variable in the properties window the same for different versions of the same product.
Change your ProductCode variable between different builds.
Now when you install the product with the same UpgradeCode already on the system, the installer will upgrade your existing product and you will only have one program in the Add/Remove window.
Create a .bat file
Write this code:
wmic product where name="SetupProgramName" call uninstall /nointeractive
cd Debug
setup.exe
Put this file in installer directory.

windows installer custom action install & uninstall both called when upgrade

Excel AddIn, VS2010, C#, Windows Installer
VS2010, Setup project, RemovePreviousVersion: True, DetectNewerInstalledVersion: True, InstallAllUsers:True
I have some install, uninstall codes in Custom Action
When I do a upgrade install, I notice, install is called first, which installs newer version, and then uninstall is called, which uninstalls the newer version. The end result is not-working AddIn left.
If I do a new install (i.e. no earlier version of AddIn), then only install is called and addin installs successfully
Installer used to work fine when I built it in VS2008, and I just converted projects to VS2010 and then the issue comes up.
Anyone know why ? thanks
You likely have RemoveExistingProducts scheduled incorrectly - I don't know if this can be changed in VS Setup Packages, but that will be the action that is causing all your pain.
I already answered in comment under my question. Now answer it explicitly for convenience in search.
I edited my MSI-file in Orca resequenced RemoveExistingProducts right after InstallInitialize (sequence number 1501). This was found in the InstallExecuteSequence table. This was originally sequence number 6550.
Pls refer Web setup project removes files after upgrade from VS2008 to VS2010

Can we instruct Visual Studio Setup to keep existing files for re-install?

I have a Windows Forms application with an installer (.msi) already created with Visual Studio. I am now creating a new installer for version 2.0 with the property RemovePreviousVersions set to true.
Now, when I install 2.0 over 1.0 it removes 1.0 and installs 2.0 completely.
Is there a way that I can tell the installer if you find some files already installed (like .xml files used for data) then don't override them?
I am trying to have my 2.0 installer serve the 2 purposes:
Install from scratch for new users
Existing users will upgrade but not lose their customizations
The deployment project in VS does not overwrite files. What happens is that since you have RemovePreviousVersions set to true, when you change your program file version and the ProductCode GUID of the setup project, it will first uninstall the previous version and then will do a clean install of the new version.
To make sure some files don't get overwritten, I usually exclude them from the Content or Primary output files (wherever they are located) and then add them separately to the setup project. Doing this, you can individually set properties for those files. The property you are looking for is called Permanent" that if set to true will never uninstall the file in question, and therefore will never overwrite it with a new version. The only drawback with this is that when you uninstall the product, the Permanent files will not get removed from their target locations, but in my case (usually local DB files), that's a good thing ;)
Cheers!
[edit] The above is true for VS 2008 SP1. Haven't tried it on other versions, so hopefully you are using the same VS version or it works for the version you use.
[edit2] Oh, also you could also use the "Condition" property to achieve something similar. If you do that, make sure that "Transitive" is set to True so the Condition is always evaluated. Haven't tried it with Conditions, but that's another option you could look at. Other than these 2, I think that's pretty much it for VS deployment projects.
When I was in a similar situation what I did was:
The files that were customized by each user and should NOT be touched by the installer were NOT included in the MSI (NOT in the Visual Studio Setup Project). When the app was run for the first time I generated the XML files through the code.
The files that were static (e.g. data that was used to populate Dropdownlists) I included in the MSI and I can update those by building a new MSI with Visual Studio.
Basically don't include customizable files in your MSI project. Create them in code for new users.
I never looked into telling the MSI not to update certain files that are included in the MSI file. The solution I came up with was perfect for me. I don't know if it can be done.
I hope this helps.

Resources