Quick Tip: Debugging Visual Studio Tools
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 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.
- Click on the '…' button, and select Dynamics.exe within your Dynamics folder.
- 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 :-).
Lee
Comments
Anonymous
July 22, 2013
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.Anonymous
July 30, 2013
Posting from Vaidy Mohan at Dynamics GP - Learn & Discuss vaidymohan.com/.../quick-tip-debugging-visual-studio-tools-developing-for-dynamics-gpAnonymous
November 10, 2013
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 appreciatedAnonymous
November 10, 2013
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 DavidAnonymous
November 10, 2013
thank youAnonymous
September 29, 2014
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.