如何使用命令行参数运行Visual Studio C#程序?

huangapple go评论65阅读模式
英文:

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中使用命令行参数运行程序,可以按照以下步骤操作:

  1. 项目
  2. BasicApp 属性
  3. 调试
  4. 启动选项
  5. 命令行参数:

在那里输入您的命令行参数,这些参数将传递给Visual Studio调试器。

请参见附加的截图。

如何使用命令行参数运行Visual Studio C#程序?

英文:

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:

  1. Project
  2. BasicApp Properties
  3. Debug
  4. Start Options
  5. Command line arguments:

After inputting your command line arguments there, the arguments will be passed to Visual Studio debugger.

Please see the attached screenshot.

如何使用命令行参数运行Visual Studio C#程序?

答案2

得分: 1

  1. 在“生成”选项卡下,点击“生成解决方案”。
  2. 使用命令行导航到 MyProject\MyProject\bin\Debug\netcoreapp3.0\
  3. netcoreapp3.0目录内,只需在命令行中执行 MyProject.exe
英文:
  1. Under the "Build" tab, click "Build Solution".
  2. Using command line, navigate to MyProject\MyProject\bin\Debug\netcoreapp3.0\.
  3. From inside the netcoreapp3.0 directory, simply execute MyProject.exe from the command line.

huangapple
  • 本文由 发表于 2020年1月4日 11:51:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/59587735.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定