1.9 配置框架:使用命令行配置提供程序接收命令行参数.pdf
直接在 launchSettings.json 中编辑命名行参数:
{
"profiles": {
"ConfigurationCommandLineDemo": {
"commandName": "Project",
"commandLineArgs": "CommandLineKey1=value1 --CommandLineKey2=value2 /CommandLineKey3=value3 -k1=k3"
}
}
}
static void Main(string[] args)
{
var builder = new ConfigurationBuilder();
//builder.AddCommandLine(args);
#region 命令替换
var mapper = new Dictionary<string, string> { { "-k1", "CommandLineKey1" } };
builder.AddCommandLine(args, mapper);
#endregion
var configurationRoot = builder.Build();
Console.WriteLine($"CommandLineKey1:{configurationRoot["CommandLineKey1"]}");
Console.WriteLine($"CommandLineKey2:{configurationRoot["CommandLineKey2"]}");
Console.ReadKey();
}