调试命令行参数Visual Studio 2017中无法识别大于(>)符号

时间:2019-02-25 15:19:11

标签: c# visual-studio-2017 command-line-arguments

我目前正在尝试调试应用程序,并且在启动应用程序时正在通过Visual Studio传递调试命令行参数,因为这是我可以调试的唯一方法。

当我在命令行参数中使用><符号时,它们将被忽略。但是,通过命令提示符调用应用程序时不会发生这种情况。

我尝试使用“&”符号gt; ,但这没有用。有人可以请教吗?

编辑:我正在使用的代码是

Processor.CommandLineArgs = My.Application.CommandLineArgs

使用它的一个例子是我通过"/output.txt />3"

My.Application.CommandLineArgs有2个项目,"/output.txt""/3"

1 个答案:

答案 0 :(得分:0)

如果您的应用程序是控制台应用程序,则只需存储您直接从Program.cs Main(string[] args)方法接收的值。它将包含您需要的所有内容。

如果您正在使用winform项目,则可以简单地编辑相同的文件,也可以从那里读取参数。这是一个全新program.cs

修改后的winform project的简单示例
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args) // just added the args here
    {
        var myParams = args; // read the values and do something. This conserve special characters

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}