42

I have an command line that uses arguments, I have no problem with this, but each time I want to test the application, I need to compile it, run the CMD, call the application with the parameters from the CMD, because I didn't find any solution that let me dynamically pass arguments to the console in Visual Studio Any idea about that? Thanks a lot!!

10 Answers 10

69

Goto Project->Properties and click the Debug Tab.

There is a section for command line arguments:

enter image description here

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

2 Comments

@Wolfgang Jacques: I'm using VS 2019 and it's still called "Command Line Arguments" for a console application.
My bad @Mitch Wheat I was looking at my .NET CORE Application.
17

If you are using VS 2022, go to the project properties -> Debug -> General, and then click on "Open debug launch profiles UI".

1 Comment

It's incredible that a 13 years old question still get new and relevant answers.
5

Right click your project in VS -> Properties -> Debug tab

There is an area where you can specify command line arguments. When you debug your project, VS will start it up with these args.

Comments

4

Go to the project properties - Debug section, and under the Start Options heading there is a section for Command line arguments.

Comments

2

In case someone is using VS Code for their project, you guys can just open the launch.json in the .vscode folder and under configurations you can just add an args key value pair like this:

"configurations": [
    {
        "name": ".NET Core Launch (console)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "args": ["What command you use to list all docker images"],
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "stopAtEntry": false
    }
]

Comments

0

It is called 'Application arguments' now enter image description here

Comments

0

Here's a solution for those who are using Visual Studio for Mac (tested on 17.3 preview). Navigate this via a top dropdown menu:

Project -> {your project name} Properties -> Run -> Configurations -> Default -> Arguments:

and enter arguments in this field.

enter image description here

Comments

0

This information used to be persisted in a ProjectName.csproj.user file. In the new .csproj format, this information is persisted in Properties\launchsettings.json. My current version of Visual Studio (17.3.2 apparently reads both of those when debugging.

If you ever see unexpected arguments, this may be the cause.

More detail here.

Comments

0

Sometimes it can be more convenient to specify the arguments in Program.cs:

static void Main(string[] args)
{
#if DEBUG
    args = ["arg1", "arg2"]; // (C# 12 collection expression)
#endif
    ...
}

Comments

0

To debug the application we need argument values and we can set the values to arguments directly in debug screen.

Then by debugging you can check if the correct values, formats etc handled.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.