次の方法で共有


An easier way to troubleshoot addins for OneNote

 

I got fed up with attaching a debugger to addins in OneNote.  The typical process (as suggested by Dan Escapa) is to have your addin open a dialog when it starts, then attach to the running process while the dialog is onscreen.  That got annoying rather quickly and I started to look for an easier way to attach to a running powertoy.  It turns out System.Diagnostics has just the method I need.

 

The easier way to attach a debugger is to call

System.Diagnostics.Debugger.Launch();

This will automatically attach your default debugger to the running process.  If you want, you can surround that line with DEBUG conditional statements like this:

 

#if DEBUG

System.Diagnostics.Debugger.Launch();

#endif

 

Now if you are using VS to create a debug build, the debugger will get attached.  Ship builds will not include these lines.

 

After getting the debugger attached, I was still forced to uninstall the previous build of my addin and run the install to get the new bits into place.  The last tip is making it easier to spoof the install for new builds so you don't have to spend time uninstalling, reinstalling or even building the setup project each time.

 

Build and install the debug app once.

Go back into Visual Studio and redirect the debug output to the folder in which you installed your app.

(optional: you can turn off building the setup project each time now)

Now when you rebuild or recompile, the old dll gets overwritten by the new, and you do not have to uninstall/reinstall for each new compile.  This works great since the GUID doesn't change once the project is created.

When you are done, be sure to rebuild the setup project.

 

These are just a couple of tweaks I discovered recently.  Nothing earth shattering - just simple time savers.

 

Questions, comments, criticisms and concerns always welcome,

John

Comments

  • Anonymous
    November 27, 2007
    This is a great tip and would save a lot of developing trouble. However when I use the above code I get a "launch for user" JIT error in dllhost.exe. Visual Studio then opens but doesn't load anything. The addin continues to work though. Also, each time I rebuild by dll and setup project file, it still installs the older version(even though I uninstall it before running the new build setup). I need to create a new setup project each time I make any changes to my dll. I tried incrementing the version of the setup, dll assembly, manually copying the new dll in the installation folder, the GAC folder but OneNote still runs the previous version of the DLL. The only way I manage to update is by creating a new setup project and installing it again. How can I make your suggestion of redirecting my dll compiled output to the installation folder work? Thanks, Ani

  • Anonymous
    November 28, 2007
    The comment has been removed

  • Anonymous
    December 03, 2007
    I wanted to pass on a story that I read in my RSS reader that John blogged about a couple weeks ago:

  • Anonymous
    December 03, 2007
    I wanted to pass on a story that I read in my RSS reader that John blogged about a couple weeks ago:

  • Anonymous
    December 27, 2007
    I received a few questions about my tip concerning a quicker way to troubleshoot addins during development.

  • Anonymous
    December 27, 2007
    I received a few questions about my tip concerning a quicker way to troubleshoot addins during development