How to Pass Command Line Arguments using Visual Studio ?

You are writing one application in Visual Studio which accepts some command line parameter to do some operation. You pass command-line arguments to the program when it’s been invoked from the command line. But how did you do it from Visual Studio?  You want to test your application, and do you really want to open the command prompt every time to pass the command line values. Really not. Here is a quick tip for all of you.

   Visual Studio enables nice features where you can do this on the Debug tab. Here are the steps to achieve this

1. Right Click on Project from Solution Explorer and Select Properties.

2. In the Project Properties Windows, Navigate to “Debug Tab”

3. You will find the text box “Command Line”

Well, here you can type the command line separated by Space.

image

Just write a simple console application to print the command line argument, and put a breakpoint to check the arguments,

image

So, each value separated by space has taken has a command-line argument. This will produce below output.

image
Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.