I’m sure there’s more than one technique for doing this, but this works for me, so I thought I’d share it.
Depending on how you count them, there are three or four steps to debugging a .net 2.0 console application by using the IDE:
Set a breakpoint in an appropriate spot
If your solution has more than one project, set your console project as the start-up
Set the command-line parameters in the debugger, if any
Execute the application in the IDE (of course)
1. Set a breakpoint in an appropriate spot
There’s a few ways of doing this, all of which involve of course selecting the line you want the breakpoint on. Breakpoints are "toggles," meaning that the same action repeated a second time will reverse the original action.
- Click on the line you want the breakpoint on, then press F9. A little red ball will appear to the left of the line. This means there is a breakpoint set here. OR-
- Where that little red ball is, you can directly click with the mouse to toggle it on/off. OR-
- Click on the line you want the breakpoint on, then select the menu item Debug/Toggle Breakpoint.
2. If your solution has more than one project, set your console proejct as the start-up
Go to Solution Explorer, which is the list of projects/files that are in the solution. If it isn’t open already, use CTRL-ALT-L to open it, or, less conveniently, the menu item View/Solution Explorer. Locate the project that is your console application and right-click on it. Select "Set as StartUp Project" from the pop-up menu. The project name will now be in bold. this indicates that it is the startup project. The startup project is the project that the IDE executes when you press F5 to start debugging (Menu: Debug/Start Debugging).
3. Set the command-line parameters in the debugger, if any
This is set on the Debug tab of your Project Properties. To get to Project Properties, first make sure to click on the project name of your console application in the Solution Explorer to select it. Then select the "Project/Properties..." menu item. (Note: The menu item will contain your project’s name, so if your project name is MyConsoleApp, the menu item will be "Project/MyConsoleApp Properties...")
Find the text box in the "Start Options" section called "Command line arguments." Enter your default command line arguments here. These are the command line arguments that will be fed to your console app by the IDE debugger when you start the debugging session by pressing F5.
4. Execute the application in the IDE
As mentioned above, press F5 to start the debugging session. Your default command line parameters will be fed to your app, and execution will pause at your breakpoint. After which, you can step through, examine variables, etc., as you please.
That’s all there is to it, but it’s one of those things that can be frustrating to try to do if you don’t know about it and/or don’t know where to look to find out how to do it.
posted Wednesday, December 12, 2007 1:35 PM by ebuatois | 0 Comments