24

I have tried to debug my custom action. I put Debugger.Break() into custom action cs. When I build custom action it creates this files:

myCustomAction.dll
myCustomAction.CA.dll
myCustomAction.pdb

In wix project I reference myCustomAction.CA.dll inside binary tags (not myCustomAction.dll). Since there doesn't exists myCustomAction.CA.pdb is this the reason that debugging doesn't work? I have tried also with messagebox and attach to process, when message box is shown. But i get the following message: Cannot find or open the PDB file.

What I'm doing wrong? I have wix 3.5 version and visual studio 2010.

3

4 Answers 4

68

Here is the article which helped me.

Just add the following code to the first line of your custom action:

System.Diagnostics.Debugger.Launch();

Then just run the installer. When it starts to execute your action, the popup window will appear with proposal to launch visual studio for debugging.

Your reference library is correct, it must be *.CA.dll. Also the approach with MessageBox would work too, but you will need to attach to the rundll32 process.

4
  • 2
    It's worth noting that as per the documentation the MsiProcessMessage (API behind session.Log) cannot be used from a ControlEvent. This will prevent your messages showing up in your log - something that had me scratching my head for a while! Feb 25, 2014 at 10:18
  • 1
    Can anyone clarify why we need to attach to the rundll32 process? I would've never realized this but that might just be a lack of Windows Installer knowledge.
    – Starceaker
    Sep 2, 2016 at 13:59
  • Your link is broken, it seems that blog has gone down.
    – IWillScoop
    Nov 13, 2018 at 16:50
  • True, links often become unavailable. But I provided the most important information from it, the answer is still valid without the link. As to MessageBox solution, you need to attach to rundll32 because this process runs dll libraries, but why actions happen in *.dll and not in *.msi - I don't know.
    – vortexwolf
    Nov 29, 2018 at 5:24
5

With DTF custom actions the two techniques are:

1) Put a MessageBox in your custom action and then attach Visual Studio to that process. When attaching, look for rundll32 process with native and CLR loaded.

2) Set the MsiBreak environment variable to the name of your entry point and reboot the machine. DTF will invoke the debugger when that custom action gets called.

Otherwise my general suggestion is to have your entry point be a very thin veneer that connects a reusable class to the MSI. I'll typically create a stand alone class that I can feed data and test everything in a console app and then wire that class up to DTF. I almost never need to debug an installer custom action.

Otherwise I know in general this works.

6
  • Do you know if the MMSIBREAK environment variable works if the custom action is part of a Merge Module that I created? Dec 10, 2015 at 18:56
  • It's been so long that I can't recall a complete solution by memory. Here's a few highlights: I don't remember if MMSIBREAK uses the CustomAction name or the Entrypoint name in the DLL. If Custom Action name the only difference with a merge module is the name is modularaized (Name.GUID instead of Name). If entry point name, no difference as there is no modularization. Dec 10, 2015 at 19:04
  • Another consideration is if the custom action is running in deferred execution with no impersonation it's running in the system context and you'll have to reboot the machine before to get the environment variable seen by MSI. This is a service control manager behavior in Windows. Dec 10, 2015 at 19:05
  • To be honest, I write most of my custom actions in such a way I can test them outside of the installer with a very thin veneer to wire it all up. This way I've done 99.9% of the dev/test and running the MSI is just a quick validation. I also tend to use the MsgBox technique instead of the ENVVAR technique because it's easier. Dec 10, 2015 at 19:06
  • Thank you very much. I made a quick test using custom action name(name.GUID) and didn't work, however using only name, didn´t work either. Yesterday my computer crashed and couldn't continue testing. I'll see how it goes today. Dec 11, 2015 at 19:29
4

Not sure what is the problem on your end but here is an article with a sample custom action and a method to debug it. It should work as explained in the following article: http://www.advancedinstaller.com/user-guide/qa-c-sharp-ca.html

1
  • As someone who is a visual learner, this helped me the most! Thank you
    – deathcat05
    Dec 9, 2021 at 16:50
1

This is in addition to the use of

System.Diagnostics.Debugger.Launch();

In a way to improve the debugging on remote system, like VM. I did some change in the wix targets file used to package the .CA.dll and I have good result.

In the Condition of the first Create Item I added a check for %(ReferenceCopyLocalPaths.extension)' == '.pdb' that way most of my dependencies .pdb are now included im my .CA.dll and allow a easier debug experience on remote system.

C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\wix.ca.targets

<Target Name="PackCustomAction"
   Inputs="@(IntermediateAssembly);@(Content);$(CustomActionContents)"
   Outputs="$(IntermediateOutputPath)$(TargetCAFileName)">

    <!-- Find all referenced items marked CopyLocal, but exclude non-binary files. -->
    <CreateItem
     Include="@(ReferenceCopyLocalPaths)"
     Condition=" '%(ReferenceCopyLocalPaths.extension)' == '.pdb' or '%(ReferenceCopyLocalPaths.extension)' == '.dll' or '%(ReferenceCopyLocalPaths.extension)' == '.exe'">
      <Output TaskParameter="Include" ItemName="CustomActionReferenceContents"/>
    </CreateItem>

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.