Quick Tip: Debugging Visual Studio Tools

Lee Butenhoff - Click for blog homepageLet's jump right in. We debug our Visual Studio applications over and over; and attaching to the test environment is among the most important, and time-consuming skills we use. (How many times have I launched GP2010 when I was thinking of GP2013?)

Of course we all simplify our testing by building the dll and pdb files directly in the Dynamics\Addins folder (right?). If not, start doing that.

Were that the only thing to learn here, that knowledge alone would be worth the price of admission. But it's a fairly obvious step, and many of us already send the built dll file to the folder.

The next level is launching and properly attaching to the right Dynamics process…automatically.

[A huge shout-out to Patrick Roth for showing me this.]

First, verify you are automatically building to the Dynamics\Addins folder. Otherwise the real value of this blog is blunted quite a bit.

  • Within Visual Studios, Solution Explorer, select the project you are working on.
  • Click on the Project menu, and click '{project name} Properties…'
    • C-Sharp:Select the Build tab, and change Output path to your Dynamics\Addins folder.
    • VisualBasic: Select the Compile tab, and change the 'Build output path:' to your Dynamics\Addins folder.

With that sorted out, we can now simplify the Debug process.

Second, in the same Properties window as the First step above, select the Debug tab – this tab is the same for both C-Sharp and VisualBasic.

  • Change the 'Start Action' radio group to 'Start external program:'
    • Click on the '…' button, and select Dynamics.exe within your Dynamics folder.
      • Your project now knows to launch Dynamics.
    • Be sure the text box contains entire path as well as the file.
  • Under 'Start Options':
    • Change the 'Command line arguments: ' text box;
    • Enter 'DYNAMICS.SET'
      • If you have a more-preferable SET file, for testing or other reasons, enter that SET file instead.
    • Change 'Working directory' to be the path where the SET file is located.
      • Generally, it's the same as the 'Start external program', but without the Dynamics.exe.
      • Be sure it ends with '/'.
  • Save the project.

Finally, as needed:

  • Build the file (F6), which automatically is built in the Dynamics\Addins folder
    • Alternatively, build and copy the dll and pdb files to the Dynamics\Addins folder
    • This is useful if Visual Studio doesn't have rights to the Dynamics folder.
  • Debug (F5).

Once it's set up properly, clicking on F5 should launch Dynamics for you. Behind the scenes, your code is automatically 'attached' to this instance of Dynamics.exe.

To fully see the power of this, place a 'Toggle Breakpoint' (F9) on the first line in your code's Initialize() method. Then click 'Start Debugging' (F5). The code should automatically break on that line after launching Dynamics. (Try doing that by 'Attaching To Process…')

Plus, once this is set up, I no longer launch GP2010 when I meant to launch GP2013 – except for the first time after an upgrade :-).