Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a Visual Studio C# program with command line arguments?

I have a very basic Visual Studio console app:

using System;

namespace BasicApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(args.Length);
        }
    }
}

I can run it just fine from inside Visual Studio by clicking the green triangle "Run" button, but I also want to be able to run it from the command line and pass it some arguments. I'm a little confused by the file structure of Visual Studio projects and I don't know too much about how compiling works. What do I need to type into the command line in order to make it run?

like image 613
wheeeee Avatar asked Mar 25 '26 10:03

wheeeee


2 Answers

If you want to run the program with command line parameters in Visual Studio, you can go to the main menu and follow below order:

  1. Project
  2. BasicApp Properties
  3. Debug
  4. Start Options
  5. Command line arguments:

After inputting your command line arguments there, the arguments will be passed to Visual Studio debugger.

Please see the attached screenshot.

command line arguments for Visual Studio debugger

like image 195
Ryu Ko Avatar answered Mar 27 '26 11:03

Ryu Ko


  1. Under the "Build" tab, click "Build Solution".
  2. Using command line, navigate to MyProject\MyProject\bin\Debug\netcoreapp3.0\.
  3. From inside the netcoreapp3.0 directory, simply execute MyProject.exe from the command line.
like image 43
wheeeee Avatar answered Mar 27 '26 12:03

wheeeee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!