WIxsharp debug custom action in console
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;
}
N.B!: I don't use WixSharp, but the below should be generic. At least some of it.
Debug Custom Actions: I just follow this procedure (since I generally use native code):
- Compile debug binaries and include in the package.
- Show a message box from the custom action.
- Use Visual Studio to attach to the process showing the dialog.
- You attach to
msiexec.exe
for native, unmanaged code, and torundll32.exe
for managed code. System context or user context process depending on how the custom action runs. - Set a break point in code directly after the dialog and let it be hit.
- This should work provided your source code matches what is in your debug binaries in the package (debugging symbols).
- You attach to
How-To Video: There is a video from Advanced Installer showing most of the process: Debug C# Custom Actions. Very good.
A step-by-step description of how to use C# (managed) custom actions with WiX.
This issue has come up a lot lately, most recently in this question / answer, section 4.
Here is some aging but good content on the topic from installsite.org: Debugging Custom Actions.
I ran a test on your own suggestion to verify that it works too for a regular WiX setup (the #if DEBUG makes the code only apply to debug builds):
#if DEBUG
System.Diagnostics.Debugger.Launch();
#endif
The other command you mention works as well for me:
Debug.Assert(false);
The main challenge is to make sure the right dll version makes it into the MSI. If you don't see expected behavior try to manually insert the dll version (debug or release) that you intend to run with into the MSI using Orca or another MSI editor tool - just to make sure the right binary is in there. I don't know how this is set up in WixSharp.
Message Boxes: To show a message box from a C# custom action:
Add a project reference to the System.Windows.Forms
namespace and system assembly (both a project reference and a using in code in other words):
using System.Windows.Forms;
<..>
[CustomAction]
public static ActionResult TestCustomAction(Session session)
{
MessageBox.Show("Hello from TestCustomAction");
return ActionResult.Success;
}
Beyond using a .NET message box, you can also use MSI's built-in Win32 dialogs via the: Session.Message
call to show a dialog. This is probably better for end user dialogs. I would use the above approach for debugging only.
For Reference: Debugging Custom Actions
C++ debugging
:
- MsiBreak environment variable
- AssertSz(FALSE, "debug CustomActionName here.")
- __asm {int 3};
- DebugBreak and __debugbreak
Managed Code
(in addition to above):
- MMsiBreak, more
Some Links (for safekeeping):
- How to read certain registry key from Wix managed bootstrapper or custom action?