3

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?

3
  • ...The path to the program, followed by the arguments? What did you try typing in that didn't work, and what happened? Commented Jan 4, 2020 at 3:53
  • If this is a .NET Framework (not .NET Core) project then the output executable will be in bin\Debug\YourProjectName.exe for Debug builds and bin\Release\YourProjectName.exe for Release builds. Commented Jan 4, 2020 at 3:56
  • @JosephSible-ReinstateMonica I wasn't sure if I need to compile it in some special way, and I had a hard time finding where the executable was stored. Commented Jan 4, 2020 at 4:28

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

1
  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.

Comments

1

In Visual Studio 2022 they created a new dialog for this:

  • Open the project's properties (right click in Solution Exporer or via main menu)
  • Select Debug
  • Click the link "Open debug launch profiles UI"
  • Type your arguments into the first field, "Command line arguments"
  • Close the window (there is no Save-Button)
  • Run your project in Debug mode to see your arguments

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.