1

I am working on a project where I need to run an action before installing a new version, this action is to check if there a product already installed and to uninstall it. I tried to add custom action in visual studio installer but I can't add a DLL file from the outside of the project so the action won't run before the installation. My application is a Microsoft office addin so that why I used visual installer because it is very simply and straightforward. Is there any another solution ?

Note : Changing product code and set DetectNewerVersion to true didn't work, 
       now I have two same product in Program and Features
Bob Arnson
  • 21,377
  • 2
  • 40
  • 47
  • It sounds like what you need is to implement a major upgrade - the built-in feature of Windows Installer to allow upgrades of existing installations. [Maybe have a look at this article from Phil Wilson on Visual Studio Installer Project upgrades](https://www.red-gate.com/simple-talk/dotnet/visual-studio/updates-to-setup-projects/) - section *"How to update your product"*. The **RemovePreviousVersions property** is important. And [here are other articles from Wilson on that site](https://www.red-gate.com/simple-talk/author/phil-wilson/). [More](https://stackoverflow.com/a/54102949/129130). – Stein Åsmul Apr 22 '21 at 21:34
  • I ran out of characters, please check the above and ask any follow-up questions. Essentially major upgrades are defined in the Upgrade table in the finished MSI and you can tweak the MSI after compiling it to fine-tune things if you absolutely have to. The SDK has information on the [Upgrade Table](https://learn.microsoft.com/en-us/windows/win32/msi/upgrade-table). And one more: [Updating Upgrade Table for an Upgrade](https://learn.microsoft.com/en-us/windows/win32/msi/updating-upgrade-table-for-an-upgrade). – Stein Åsmul Apr 22 '21 at 21:41
  • I'm able to update the product, but when I open program and features I see two products instead of one. I followed the same steps mentions in Phil article. – wakopox568 Apr 22 '21 at 21:52
  • When you have two items in add / remove then the major upgrade has failed. There are several possible reasons, most likely you didn't set the right combination of parameters needed, or there are [other reasons for failed major upgrads](https://stackoverflow.com/a/56991527/129130). Note that that list is written in general for MSI - with focus on WiX. In your case you should check that article again and verify that all parameters required are set. Also not that you can not upgrade a product installed per user with a per machine installation - at least not automatically I believe (new features?) – Stein Åsmul Apr 22 '21 at 21:58
  • Yeah I found the reason maybe because of that "An Everyone install does not upgrade a Just me install, and vice versa." according to Phil Wilson – wakopox568 Apr 22 '21 at 21:58
  • Yes, that is probably the reason. I am not sure if you can change the dialogs to disallow this option? If you want a custom action to check then that is not entirely trivial. You can use the upgrade code to enumerate products via automation / scripting or use [C++ methods described here](https://stackoverflow.com/a/15659159/129130). [Visual Studio Setup – projects and custom actions](https://www.red-gate.com/simple-talk/dotnet/visual-studio/visual-studio-setup-projects-and-custom-actions/). – Stein Åsmul Apr 22 '21 at 22:05
  • [Here is an old answer of mine on finding related products](https://stackoverflow.com/a/56909918/129130). Not sure if it makes a lot of sense, but please have a quick look. I think it shows how to find machine and user installations. I have other code you can try for that too, but give that a check first. [Slight digression for migrating from per-user to per-machine for InstallShield - but this is a different product](https://stackoverflow.com/a/12291807/129130) – Stein Åsmul Apr 22 '21 at 22:07
  • Ok got it. Is there a way to uninstall the product before installing the new version. I want to uninstall the per user and install to everyone. – wakopox568 Apr 23 '21 at 07:43
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/231524/discussion-between-stein-asmul-and-wakopox568). – Stein Åsmul Apr 23 '21 at 16:49

1 Answers1

0

Here you can find InstallExecuteSequence numbers. You just should put yours custom action in right place, for example you can set Sequence=750 - it will be run before CostInitialize.

Also here's video tutorial how to use orca.exe. It's amazing app to check and debug your msi. In your case you can check is your CustomAction in right place or you should change number, or even your custom action isn't working.

And about "I tried to add custom action in visual studio installer but I can't add a DLL file from the outside of the project so the action won't run before the installation". I can't get what do you mean, but seems that you can't add dll with custom actions. Here's tutorial about it.

ba-a-aton
  • 574
  • 1
  • 4
  • 14