How to debug custom bootstrap application?
Asked Answered
N

7

19

I am using Burn for MSIs package. I am using Votive (Visual Studio) & my own custom BA instead of WiXBA. I tried to debug custom BA using Debugger.Launch(). But when I start debugging, error messages occur.

No symbols are loaded for any call stack frame. The source code cannot be displayed

I realized that package.exe links CustomBA dll which located at C:\Documents and Settings\user\Local Settings\Temp\{GUID}\. {GUID} is always changed. So, whenever I run package.exe, always directory is changed.

I think that is the reason to occur errors.

In Visual Studio, When I started package.exe with CustomBA dll which located at absolute path (.../Debug/bin/CustomBA.dll). But after execute the package.exe, it links to Local Settings\Temp\{GUID} directory. So, when we start debugging and attached to CustomBA dll, CustomBA dll's directory is dynamically changed and No symbols are loaded error occurs.

  • Why package.exe links dll which located at C:\Documents and Settings\user\Local Settings\Temp\{GUID}\? Can we choose the path for dll statically?
  • If we can't choose the dll path statically, how can I use debugging functions for CustomBA?
Nonfulfillment answered 12/6, 2012 at 17:44 Comment(0)
E
28

To debug a Bootstrapper Application, you'll want both your Bundle .wixproj and BA .csproj (or .vcxproj if you're doing a native .dll) in the same solution and the Bundle project should be dependent on the BA project so rebuilds work correctly. The following steps should allow you to step into your code.

Note: Ensure you are not running Visual Studio elevated. If you have UAC disabled, re-enable it. These steps will not work correctly if Visual Studio is running elevated.

  1. Rebuild the project. This ensures you have a Bundle created with an updated BA.dll inside it.
  2. Right click on the BA .csproj in Solution explorer and select Set as StartUp Project. The BA .csproj should be bold.
  3. Right click on the BA .csproj and choose Properties.
  4. On the Properties for the BA .csproj select the Debug tab.
  5. In the Debug tab, choose the radio button labeled Start external program
  6. Browse to the path where your Bundle is built.

Now, you can press F5 and start debugging. Remember that any time you change the BA .csproj, you also need to ensure the Bundle .wixproj is rebuilt. Otherwise, the Bundle will launch with your old BA in it and the debugger will find the newly built BA's .pdbs don't match.

Extra credit: if you disable Just My Code in the debugger settings and download the pdbs.zip and sources.zip for the matching build of your WiX install, you can actually step through the Burn code as well as your BA to see how everything works together.

Essequibo answered 9/4, 2013 at 22:33 Comment(4)
Just curious is you'd be interested in expounding on the reason why the process doesn't work correctly if VS is running elevated...Micah
Rob, it would be super stress-relieving to allow Wix Projects to have Run/Debug capabilities. Is this missing intentionally? As you point out, even this workaround requires a double-build to ensure you're running the code you think you're running. "Any time you change the BA.csproj" is most of the time you'd intend to debug there.Iconology
Can you please advise how to step into burn? I've pointed VS at the pdb, rebuilt burn in debug mode, but it always seems to be skipped. The breakpoint I set in msiengine.cpp is "errored" and tells me that it will be skipped because no symbols were loaded for the document.Joselynjoseph
I am using your process. Installer fires up when I click start. But, my breakpoints are never hit although my custom BA shows up. I am using Wix 3.10 with VS 2015 Community. Any hints are appreciated.Filariasis
G
10

I followed Rob's suggestion in this post but sadly i couldn't get it to work for me (Visual Studio 2015, Wix 3.10.3, managed Bootstrapper Application using WixWPF). No breakpoints are ever hit. I noticed the debugger attaches itself to the wrong process, the installer has two running processes (im guessing the BA and the Bundle). When I changed the process the breakpoints were hit but my managed BA has code i want to debug before the debugger actually gets attached

Ive managed to find a solution where the application will not start until the debugger is attached. I put this code in my constructors code-behind file (in the DEBUG block) for my managed BA like so...

public MainWindow()
{
#if DEBUG
    // Do not start until debugger attached
    while(!System.Diagnostics.Debugger.IsAttached)
    {
        System.Threading.Thread.Sleep(1000);
    }
#endif
    InitializeComponent();
    InstallData = new InstallerInfo();
}

Now when i compile my managed Bootstrapper Application (with Debug) along with the Bundle and run it, the application will not start until you attach to the managed Bootstrapper Application Tools > Attach to Process > Find your exe in the list.

Gilson answered 10/8, 2016 at 21:35 Comment(1)
Thanks for the pointer. This seems to be working for me too in same setup as yours.Filariasis
N
5

You cannot run your custom BA in debug mode from Visual Studio.

What you can do is to run the generated exe file and then attach Visual Studio to the process which would let you debug it. (In the menu: Tools > Attach to Process > Find your exe in the list)

Numerary answered 21/6, 2012 at 10:10 Comment(1)
+1: worked for me with UAC off. FWIW, I also threw in a System.Threading.Thread.Sleep(5000); at the beginning of Run() in my BA, so that I'd have time to attach.Micah
I
1

As many other answers suggested above, the debugger is attached to the process that runs installer executables. You will need to manually attach the debugger to the UI process that is spawned under a temp folder like many have done before.

To allow for child processes to be attached automatically without all the extra code mentioned, you do can as mentioned:

  1. Install the visual studio extension called MicrosoftChildProcessDebuggingPowerTool.
  2. Set the executable in debug start action just like Rob mentioned.
  3. Enable native code debugging (important)
  4. Turn on Child Process Debugging by Debug -> Other Debug Targets -> Child Process Debugging Settings -> Enable child process debugging -> Save
Indemnification answered 14/9, 2020 at 18:26 Comment(0)
S
1

The only thing which really works is:

protected override void Run()
{
    Debugger.Launch();
}

in your bootstrapper UI application (BootstrapperApplication descendant). Then start the built bootstrapper.exe from the explorer and reuse your Visual Studio instance in "Choose Just-In-Time Debugger" window. Don't forget to clean the solution before re-building. This prevents sometimes from debugging correctly.

PS: when there are problems with finding the correct pdb's of your bootstrapper UI assembly, choose the same architecture than the bootstrapper setup. Mixing architectures can lead to debugging problems.

Cheers

Schmid answered 22/1, 2021 at 8:46 Comment(0)
E
0

Rob's solution doesn't work. Approach of AhmedBM works but it still can be further streamlined so that VS runs WiX bootstrapper process and then immediately attaches to the child process.

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
    //kill old ones if any
    System.Diagnostics.Process.Start(@"c:\Windows\System32\taskkill.exe", "/F /IM Bootstrapper.exe /T");
    System.Threading.Thread.Sleep(1000);
    //start new one
    System.Diagnostics.Process.Start(@"<solution path>\src\Bootstrapper\bin\Debug\Bootstrapper.exe");
    System.Threading.Thread.Sleep(1000);

    foreach (Process proc in DTE.Debugger.LocalProcesses)
    {
        if (proc.Name.ToString().Contains(@".cr\Bootstrapper.exe"))
        {           
                proc.Attach();
                return;  
        }
    }
    System.Windows.MessageBox.Show("Bootstrapper Process was not found.");
}

The only problem is that you need DTE object. In earlier versions of VS we had Macroses where it was accessible. But in VS 2017 we don't have them. So, you can quickly make simple VS extension and add the command running the code there. Or use already existing extension, some of them allow to make custom commands.

Electronic answered 4/2, 2020 at 15:14 Comment(0)
C
0

Stick a MessageBox as the first line in your BA. Run the BA and the MessageBox will show up. Before hitting OK, From the menu DEBUG|Attach to Process, select your BA and Attach. Then hit the MessageBox's OK. Now your debugging!

Chromatogram answered 4/9, 2021 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.