1

OS: Windows 10 Enterprise N
Dev Environment: VS2022 (64-Bit) Professional (7.5)
Application: VSTO Add-In (Outlook 32-Bit)

The custom action I have closes Outlook during Install. That's working. However, it's not calling my UnInstall code which also closes Outlook.

Is there a way to step through this code?

CUSTOM ACTION CODE

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;

namespace MySetupCustomActions
{
    [RunInstaller(true)]
    public class AddCustomizations: Installer
    {
        public AddCustomizations() : base() { }

        // Override the 'Install' method.
        public override void Install(IDictionary savedState)
        {
            base.Install(savedState);    

            KillProcess("outlook");               

        }
        // Override the 'Commit' method.
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
            KillProcess("outlook");
        }
        // Override the 'Rollback' method.
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
            KillProcess("outlook");
        }

        private void KillProcess(string processName)
        {
            try
            {
                var procs = Process.GetProcessesByName(processName);
                foreach (var p in procs) { p.Kill(); }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        
        static void Main()
        {
           
            
        }
    }
}
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
ezG
  • 391
  • 1
  • 17
  • Added an answer. Lots of links - don't despair. The video should help you quickly. Do use WiX - it will help to support any new requirements you get. Conditions are hairy - use the approach to show message boxes from custom actions to see what is going on. As you know, conditions control when custom actions actually run (install, uninstall, repair, major upgrade, etc...). It is common to condition a custom action so it never runs at all or runs amok - so to speak. – Stein Åsmul Mar 01 '23 at 23:49

2 Answers2

1

Use WiX: Are you using WiX already? Recommend you use WiX instead of Visual Studio Installation Projects. Here are some reasons. WiX quick start resources. I have an answer on WiX CA debugging: MSI Custom Action Debugging. Maybe go straight to the video demonstration of the Visual Studio debugger used with WiX / MSI to see it quickly demonstrated. I have never tried with VS projects (don't have the need to use it).

Samples: Some further resources:

Conditioning: Custom Action conditioning is very error prone. I use message boxes during testing to determine when a custom action runs. See description here: How to execute conditional custom action on install and modify only?. And then there is this walk-through of what complex conditions actually end up causing: Wix Tools update uses old custom actions

Some further links on MSI Conditions:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
0

Well, somehow my "UnInstall" override is missing!!!

UGH!!! Too many late nights.

It's working.

That said, I would still like to know how one steps through this code? I'll post in a new thread.

ezG
  • 391
  • 1
  • 17