gpt4 book ai didi

c# - 将 #if DEBUG 与 Main 参数一起使用

转载 作者:太空宇宙 更新时间:2023-11-03 18:07:12 26 4
gpt4 key购买 nike

我在控制台应用程序中编写了这段代码:

#if DEBUG
args = new[] {"4478676e34432432434"};
#endif

if (args == null)
{
Console.WriteLine("Please enter IP for single testing for now.");
}

当测试人员想要测试我的应用程序但忘记输入运行应用程序的参数时,我仍然希望他看到该消息。但现在它不这样做了。这是否意味着我应该将 build 也放在“Release” 上?这个 "DEBUG" 是指我们在 VS IDE 中还是在调试/发布版本中?

最佳答案

您可以给他们一个发布版本。这可能是最好的,因为@JoeEnos 在他对您的问题的评论中指出的原因。

无论哪种方式,最好在项目属性中指定命令行参数,而不是在条件 #if DEBUG 中指定。但是,Visual Studio 会将它们添加到本地项目属性中,因此它不会与项目一起 checkin ,这意味着其他开发人员不会拥有您使用的命令行参数。根据我的经验,我发现这是一件好事。

有关添加用于调试的命令行参数的信息,请查看此 MSDN entry

To specify command-line arguments for debugging

With a project selected in Solution Explorer, on the Project menu, click Properties.

Click the Debug tab.

In the Command line arguments field, enter the command-line arguments you wish to use.

关于c# - 将 #if DEBUG 与 Main 参数一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25272409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com