Reputation: 15966
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
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
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
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.
Upvotes: 0
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.
Upvotes: 0
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
Reputation: 300827
Goto Project->Properties
and click the Debug
Tab.
There is a section for command line arguments:
Upvotes: 69
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
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