25

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

69

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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!
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.
Your link is broken, it seems that blog has gone down.
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.
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 Comments

Do you know if the MMSIBREAK environment variable works if the custom action is part of a Merge Module that I created?
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.
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.
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.
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.
|
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 Comment

As someone who is a visual learner, this helped me the most! Thank you
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>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.