我试图查看使用CommandLineParser 包和 Visual Studio Professional 2015(更新 3)解析命令行参数时发生的错误。这是我正在使用的代码:
using System;
using System.IO;
namespace SampleParser
{
class Program
{
static void Main(string[] args)
{
// Set the CommandLineParser configuration options.
var commandLineParser = new CommandLine.Parser(x =>
{
x.MutuallyExclusive = true;
x.HelpWriter = Console.Error;
x.IgnoreUnknownArguments = false;
});
// Parse the command-line arguments.
var options = new CommandLineOptions();
var optionsAreValid = commandLineParser.ParseArguments(args, options);
if (!optionsAreValid)
{
return;
}
}
}
}
我期待在窗口中看到一些有关导致optionsAreValid
设置为false的问题的有用信息。Debug > Windows > Output
但是,什么都没有出现……我是不是做错了什么,是我找错了地方,还是在我看到这些信息之前需要切换其他设置?
更新#1
这是在(成功)解析后对命令行选项进行建模的类:
namespace SampleParser
{
class CommandLineOptions
{
[Option(HelpText = @"When set to ""true"", running the application will not make any changes.", Required = false)]
public bool Preview { get; set; }
[HelpOption]
public string GetUsage()
{
return HelpText.AutoBuild(this, current => HelpText.DefaultParsingErrorsHandler(this, current));
}
}
}