C# 如何调试将参数传递给 Main 的程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9478603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug program that pass argument to Main?
提问by KMC
I am writing a Console application that pass a string array of arguments to the Main. Using the F5 to debug would throw me an exception because I have not pass the arguments.
我正在编写一个控制台应用程序,它将参数的字符串数组传递给 Main。使用 F5 进行调试会抛出异常,因为我没有传递参数。
The way I debug/test the code where I can pass arguments is to build the solution and then run the .exe on the command prompt, but it's very inconvenient.
我调试/测试可以传递参数的代码的方法是构建解决方案,然后在命令提示符下运行 .exe,但这非常不方便。
Is there a way to pass arguments to debug?
有没有办法传递参数进行调试?
采纳答案by Jon Skeet
From within Visual Studio? Absolutely - go to the project's property designer, select the Debug pageand you can set the command line arguments, as well as the working directory. See MSDNfor more information.
从 Visual Studio 中?绝对 - 转到项目的属性设计器,选择调试页面,您可以设置命令行参数以及工作目录。有关更多信息,请参阅MSDN。
回答by Adam Pope
In Visual Studio right-click on the project name in Solution Explorer. Select Properties from the list. Go to the Debug tab. You can put your parameters in Command Line Arguments textbox.
在 Visual Studio 中,右键单击解决方案资源管理器中的项目名称。从列表中选择属性。转到调试选项卡。您可以将参数放在命令行参数文本框中。
回答by Ken Wayne VanderLinde
回答by Jon Egerton
You should be able to enter command line arguments in the Project Settings dialog.
您应该能够在“项目设置”对话框中输入命令行参数。
There's some info here: http://msdn.microsoft.com/en-us/library/2kf0yb05.aspx
这里有一些信息:http: //msdn.microsoft.com/en-us/library/2kf0yb05.aspx

