Search code examples
c#wixwindows-installerwixsharp

WIxsharp debug custom action in console


I have a custom action project which compiles to a .dll, I want to be able to step through my custom actions, i know the package can be changed to wixsharp.bin but this dosn't seen very practical. Regardless, I still tried this method but it didn't hit my breakpoints.

Wix uses: System.Diagnostics.Debugger.Launch(); which launches the action in debug, this dosn't seem to work for wixsharp but it's expected result is what i am trying to achieve.

I have seen that debug.assert can be used for debugging and i have also seen references to #if DEBUG #endif How do i debug correctly?

    [CustomAction]
    public static ActionResult CustomAction(Session session)
    {
        Debug.Assert();
        MessageBox.Show("Hello World!" + session[IISSessions.AppPoolName], "External Managed CA");

        return ActionResult.Success;
    }

Solution

  • Not quite sure what was causing the problem, I deleted my bin folder and then ran a build and it now seems to be working. System.Diagnostics.Debugger.Launch() does work correctly it needs to be contained within an #if DEBUG as @Stein Åsmul stated. Once built in DEBUG run the outputed .msi, you will be prompted to open an instance of visual studio when you hit your custom action during install.

       [CustomAction]
        public static ActionResult CustomAction(Session session)
        {
    
        #if DEBUG
                System.Diagnostics.Debugger.Launch();
        #endif
                MessageBox.Show("Hello World!" + session[IISSessions.AppPoolName], "External Managed CA");
    
                return ActionResult.Success;
         }