我尝试使用参数运行/调试的程序位于
${workspaceFolder}/src/GradeBook/Program.cs
看起来像这样:
using System;
namespace GradeBook {
class Program {
static void Main(string[] args) {
String greeting = args.Length > 0 ? $"Hello {args[0]}!" : "Hello!";
Console.WriteLine(greeting);
}
}
}
在 VS Code 侧边栏中
create a launch.json file
C#
。 launch.json
已创建并打开。Add Configuration
{} .NET: Launch Executable file (Console)
"preLaunchTask": "build",
"program"
路径"args"
,例如"Jose Ville"
launch.json
看起来像这样:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/src/bin/Debug/net8.0/GradeBook.dll",
"args": ["Jose Ville"],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
现在,当您运行或调试程序时,
"Jose Ville"
作为参数传入,"Hello Jose Ville!"
将被写入控制台。