在 Visual Studio Code 中使用命令行提示运行 C# 程序 [英] Running a C# program with command line prompts in Visual Studio Code

查看:26
本文介绍了在 Visual Studio Code 中使用命令行提示运行 C# 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio Code 中运行一个用 C# 编写的继承项目.为了运行此应用程序,它需要接受命令行输入(-t、-h 等).我如何从 Visual Studio 内部对此进行测试?

I am running an inherited project written in C# inside Visual Studio Code. In order for this application to run, it needs to take command line input (-t, -h, etc). How do I test this from inside Visual Studio?

目前(我一直在学习 dotnet、C#、VS 等)我有一个 hello world 程序,我可以从 vsc 的终端运行.出于某种原因,我无法确定,可能是我是如何安装它的,无法识别 dotnet run - 我必须向它提供一个指向 dotnet.exe 的显式路径:C:Program Filesdotnetdotnet.exe 运行

Currently (I've been learning dotnet, C#, VS, etc as I go) I have a hello world program I can run from vsc's terminal. For a reason I haven't been able to pinpoint, probably how I installed it, dotnet run isn't recognized - I have to feed it an explicit path to dotnet.exe: C:Program Filesdotnetdotnet.exe run

当程序需要命令行输入时,我该怎么做?我在 C:Program Filesdotnetdotnet.exe run -t 的黑暗中进行的射击可以预见地不起作用,但我不知道还能尝试什么.

How can I do this when the program requires command line input? My shot in the dark of C:Program Filesdotnetdotnet.exe run -t predictably didn't work, but I'm not sure what else to try.

谢谢!

推荐答案

如果您使用 dotnet.exe run 来启动您的应用程序,您需要添加 -- 开关指示 dotnet.exe 将参数传递给应用程序的语句.例如

If you are using dotnet.exe run to start your application you need add the -- switch statement to instruct dotnet.exe to pass the arguments to your application. For example

微软文档

dotnet.exe run -- -arg1 -arg2 (etc) 注意 --dotnet 参数之后和你的程序之前参数.

dotnet.exe run -- -arg1 -arg2 (etc) notice the -- after the dotnet arguments and before your program specific arguments.

GitHub 问题

这篇关于在 Visual Studio Code 中使用命令行提示运行 C# 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆