英文:
How do I run a Visual Studio C# program with command line arguments?
问题
我有一个非常基本的Visual Studio控制台应用程序:
using System;
namespace BasicApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(args.Length);
}
}
}
我可以通过在Visual Studio中点击绿色三角形的“运行”按钮来成功运行它,但我也想能够从命令行运行它并传递一些参数。我对Visual Studio项目的文件结构有点困惑,也不太了解编译的工作原理。我需要在命令行中输入什么来使其运行?
英文:
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?
答案1
得分: 2
如果您想在Visual Studio中使用命令行参数运行程序,可以按照以下步骤操作:
- 项目
- BasicApp 属性
- 调试
- 启动选项
- 命令行参数:
在那里输入您的命令行参数,这些参数将传递给Visual Studio调试器。
请参见附加的截图。
英文:
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:
- Project
- BasicApp Properties
- Debug
- Start Options
- Command line arguments:
After inputting your command line arguments there, the arguments will be passed to Visual Studio debugger.
Please see the attached screenshot.
答案2
得分: 1
- 在“生成”选项卡下,点击“生成解决方案”。
- 使用命令行导航到
MyProject\MyProject\bin\Debug\netcoreapp3.0\
。 - 在
netcoreapp3.0
目录内,只需在命令行中执行MyProject.exe
。
英文:
- Under the "Build" tab, click "Build Solution".
- Using command line, navigate to
MyProject\MyProject\bin\Debug\netcoreapp3.0\
. - From inside the
netcoreapp3.0
directory, simply executeMyProject.exe
from the command line.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论