How do I debug and Step through a Visual Studio Setup project?

164 views Asked by At

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()
        {
           
            
        }
    }
}
2

There are 2 answers

0
ezG On

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.

0
Stein Åsmul On

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: