【问题标题】:Setting default debug commandline arguments by code?通过代码设置默认调试命令行参数?
【发布时间】:2013-04-13 00:05:15
【问题描述】:

有没有一种方法可以设置默认调试命令行参数或默认应用程序参数,而无需在项目设置的“调试”选项卡中设置参数?

我的意思是如果我能做这样的事情:

Module Main

#If DEBUG Then
  ' Debug Commandline arguments for my application:
  My.Application.CommandLineArgs = "-Sleep 5 -Interval 50 -Key CTRL+C"
#End If

...Sub main()
   GetArguments() ' A function wich gets the arguemnts that I've set.
...etc...

End module

【问题讨论】:

    标签: c# .net vb.net arguments command-line-arguments


    【解决方案1】:

    您可以创建一个类来从命令行抽象您的其他代码。对于调试编译,它将返回固定字符串,否则将返回真实的 Enviroment.CommandLine。

    public static class CommandLineHelper
    {
      public static string GetCommandLine()
      {
       #if DEBUG
         return "my command line string";
       #else
         return Enviroment.CommandLine;
       #endif
      }
    }
    

    【讨论】:

    • 感谢您的回答,我知道该怎么做,您能给我参考 MSDN 或其他东西让我开始尝试吗?
    • 我已经添加了基本的C#示例,如果需要,您可以尝试将其转换为VB。
    • 谢谢你,现在我明白你说什么了。
    猜你喜欢
    • 2017-03-08
    • 2013-07-05
    • 2011-03-06
    • 2014-04-24
    • 2018-11-18
    • 2015-01-15
    • 2010-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多