Debugging Console Applications in VB.NET
In this small article, I will show you how you can set command line arguments and other project properties in Visual Studio so you don’t have to pass these arguments each time you run the application. This article also shows you how you can read command line arguments in your code.
Last week somebody asked me a question how to set default command line arguments when debugging a console application in Visual Studio.
Debugging a console application is little tricky when you need to pass the command line arguments. However, Visual Studio makes your life pretty simpler. In this small article, I will show you how you can set the command line arguments and other project properties in Visual Studio so you don't have to pass those arguments each time you run the application. This article also shows you how you can read command line arguments in your code.
To set default command line arguments, you go to your console application project properties, click on Configuration Properties -> Debugging options and set command line arguments in the Command line arguments text box. See Figure 1.
The Command object gives you all the commands passed to the application from command line. The following code loops through the command line arguments and parse them.
Dim strCommandLine As String = Microsoft.VisualBasic.Command()
Dim delimiter As Char() = " ".ToCharArray()
Dim arrCommands() As String = strCommandLine.Split(delimiter)
Dim strCommand As String
' Loop through each command
For Each strCommand In arrCommands
Dim str As String
str = strCommand
The Debugging tab of the project properties has options. The first option is Start Action. The default selection is Start Project, which means the current project is the start project. However, you can also specify if you want to make other programs and URLs as start action using rest two options. For example, if you want to run some other exe before running your projects, you can set the exe as Start external program. See Figure 2.
Working directory option specifies the working directory of the program being debugged. If you want to debug program on a remote machine, you can check Use Remote machine option.