Omar Abid
Omar Abid

Reputation: 15966

How to pass arguments when debugging a dot net application

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!!

Upvotes: 42

Views: 36218

Answers (9)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112772

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

Upvotes: 0

gyurebalint
gyurebalint

Reputation: 11

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
    }
]

Upvotes: 1

Petter Hesselberg
Petter Hesselberg

Reputation: 5518

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.

Upvotes: 0

Tomasz Cz.
Tomasz Cz.

Reputation: 334

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

Upvotes: 0

Gambali
Gambali

Reputation: 161

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

Upvotes: 16

Ben-Coden
Ben-Coden

Reputation: 126

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

Upvotes: 0

Mitch Wheat
Mitch Wheat

Reputation: 300827

Goto Project->Properties and click the Debug Tab.

There is a section for command line arguments:

enter image description here

Upvotes: 69

scott
scott

Reputation: 746

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

Upvotes: 4

Andy White
Andy White

Reputation: 88475

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.

Upvotes: 5

Related Questions