【发布时间】:2018-03-26 08:51:59
【问题描述】:
我正在使用CommandLineParser 并将示例代码粘贴到我的示例项目中。我收到很多错误,例如:
严重性代码描述项目文件行抑制状态 错误 CS0246 找不到类型或命名空间名称“DefaultValue”(是否缺少 using 指令或程序集引用?)
严重性代码 描述 项目文件行抑制状态 错误 CS0246 找不到类型或命名空间名称“ParserStateAttribute”(您是否缺少 using 指令或程序集引用?)
我不包括图书馆或其他东西吗?我已经包含了CommandLine,并且我已经通过nuget https://archive.codeplex.com/?p=commandline安装了这个包。
using System;
using CommandLine;
namespace Foo
{
class Program
{
class Options
{
[Option('r', "read", Required = true,
HelpText = "Input file to be processed.")]
public string InputFile { get; set; }
[Option('v', "verbose", DefaultValue = true,
HelpText = "Prints all messages to standard output.")]
public bool Verbose { get; set; }
[ParserState]
public IParserState LastParserState { get; set; }
[HelpOption]
public string GetUsage()
{
return HelpText.AutoBuild(this,
(HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
}
}
static void Main(string[] args)
{
var options = new Options();
if (CommandLine.Parser.Default.ParseArguments(args, options))
{
// Values are available here
if (options.Verbose) Console.WriteLine("Filename: {0}", options.InputFile);
}
}
}
}
【问题讨论】:
-
那个例子已经过时了。实例参考github仓库:github.com/commandlineparser/commandline
-
@Evk 谢谢,我看过这个,我也试过那个例子。我在执行解析的行中遇到另一个错误:
Does not contain a definition for .WithParsed