Quick Tip: Debugging Visual Studio Tools

Lee Butenhoff - Click for blog homepageThis is a reposting of an article Lee Butenhoff originally wrote on my Developing for Dynamics GP blog.

Let’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 DynamicsAddins 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 DynamicsAddins 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 DynamicsAddins folder.
    • VisualBasic: Select the Compile tab, and change the ‘Build output path:’ to your DynamicsAddins 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 DynamicsAddins folder
    • Alternatively, build and copy the dll and pdb files to the DynamicsAddins 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 :-).

Lee

This article was originally posted on the Developing for Dynamics GP Blog and has been reposted on http://www.winthropdc.com/blog.

6 thoughts on “Quick Tip: Debugging Visual Studio Tools

  1. One thing to note is that the "start and attach" isn't supported with the free version of Visual Studio.  Unless things are different in the most recent version, one limitation of the free version is that we cannot "attach to process" either this way or after the fact.
    So while you can still build a vstools addin using the Express version, you cannot easily debug it.

    Like

  2. Dear Sir
    Kindly support me in debugging GP  as i created GPAddin dll using VS 2008 and when i try to debug it and putting Break point it raise  "no symbols have been loaded for this document"
    and i need to debug urgent as it takes long time to run application and get values in message
    your feedback is highly appreciated

    Like

  3. Hi Mona
    As mentioned earlier the blog is not a vehicle for support. Please either log a support case or post on the community forums.  As this is urgent I would suggest logging a support case.
    Thanks
    David

    Like

  4. Saludos, amigo Buttenhoff.
    Seguí los pasos sugeridos, correctamente explicados y es lo que necesitaba.
    Permítame agradecerle por su contribución. Me ha funcionado perfectamente.
    Saludos.

    Like

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.