1 <?xml version="1.0"?>
\r
4 <name>Microsoft.Extensions.Configuration.CommandLine</name>
\r
7 <member name="T:Microsoft.Extensions.Configuration.CommandLineConfigurationExtensions">
\r
9 Extension methods for registering <see cref="T:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider"/> with <see cref="T:Microsoft.Extensions.Configuration.IConfigurationBuilder"/>.
\r
12 <member name="M:Microsoft.Extensions.Configuration.CommandLineConfigurationExtensions.AddCommandLine(Microsoft.Extensions.Configuration.IConfigurationBuilder,System.String[])">
\r
14 Adds a <see cref="T:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider"/> <see cref="T:Microsoft.Extensions.Configuration.IConfigurationProvider"/>
\r
15 that reads configuration values from the command line.
\r
17 <param name="configurationBuilder">The <see cref="T:Microsoft.Extensions.Configuration.IConfigurationBuilder"/> to add to.</param>
\r
18 <param name="args">The command line args.</param>
\r
19 <returns>The <see cref="T:Microsoft.Extensions.Configuration.IConfigurationBuilder"/>.</returns>
\r
22 The values passed on the command line, in the <c>args</c> string array, should be a set
\r
23 of keys prefixed with two dashes ("--") and then values, separate by either the
\r
24 equals sign ("=") or a space (" ").
\r
27 A forward slash ("/") can be used as an alternative prefix, with either equals or space, and when using
\r
28 an equals sign the prefix can be left out altogether.
\r
31 There are five basic alternative formats for arguments:
\r
32 <c>key1=value1 --key2=value2 /key3=value3 --key4 value4 /key5 value5</c>.
\r
36 A simple console application that has five values.
\r
38 // dotnet run key1=value1 --key2=value2 /key3=value3 --key4 value4 /key5 value5
\r
40 using Microsoft.Extensions.Configuration;
\r
43 namespace CommandLineSample
\r
45 public class Program
\r
47 public static void Main(string[] args)
\r
49 var builder = new ConfigurationBuilder();
\r
50 builder.AddCommandLine(args);
\r
52 var config = builder.Build();
\r
54 Console.WriteLine($"Key1: '{config["Key1"]}'");
\r
55 Console.WriteLine($"Key2: '{config["Key2"]}'");
\r
56 Console.WriteLine($"Key3: '{config["Key3"]}'");
\r
57 Console.WriteLine($"Key4: '{config["Key4"]}'");
\r
58 Console.WriteLine($"Key5: '{config["Key5"]}'");
\r
65 <member name="M:Microsoft.Extensions.Configuration.CommandLineConfigurationExtensions.AddCommandLine(Microsoft.Extensions.Configuration.IConfigurationBuilder,System.String[],System.Collections.Generic.IDictionary{System.String,System.String})">
\r
67 Adds a <see cref="T:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider"/> <see cref="T:Microsoft.Extensions.Configuration.IConfigurationProvider"/> that reads
\r
68 configuration values from the command line using the specified switch mappings.
\r
70 <param name="configurationBuilder">The <see cref="T:Microsoft.Extensions.Configuration.IConfigurationBuilder"/> to add to.</param>
\r
71 <param name="args">The command line args.</param>
\r
72 <param name="switchMappings">
\r
73 The switch mappings. A dictionary of short (with prefix "-") and
\r
74 alias keys (with prefix "--"), mapped to the configuration key (no prefix).
\r
76 <returns>The <see cref="T:Microsoft.Extensions.Configuration.IConfigurationBuilder"/>.</returns>
\r
79 The <c>switchMappings</c> allows additional formats for alternative short and alias keys
\r
80 to be used from the command line. Also see the basic version of <c>AddCommandLine</c> for
\r
81 the standard formats supported.
\r
84 Short keys start with a single dash ("-") and are mapped to the main key name (without
\r
85 prefix), and can be used with either equals or space. The single dash mappings are intended
\r
86 to be used for shorter alternative switches.
\r
89 Note that a single dash switch cannot be accessed directly, but must have a switch mapping
\r
90 defined and accessed using the full key. Passing an undefined single dash argument will
\r
91 cause as <c>FormatException</c>.
\r
94 There are two formats for short arguments:
\r
95 <c>-k1=value1 -k2 value2</c>.
\r
98 Alias key definitions start with two dashes ("--") and are mapped to the main key name (without
\r
99 prefix), and can be used in place of the normal key. They also work when a forward slash prefix
\r
100 is used in the command line (but not with the no prefix equals format).
\r
103 There are only four formats for aliased arguments:
\r
104 <c>--alt3=value3 /alt4=value4 --alt5 value5 /alt6 value6</c>.
\r
108 A simple console application that has two short and four alias switch mappings defined.
\r
110 // dotnet run -k1=value1 -k2 value2 --alt3=value2 /alt4=value3 --alt5 value5 /alt6 value6
\r
112 using Microsoft.Extensions.Configuration;
\r
114 using System.Collections.Generic;
\r
116 namespace CommandLineSample
\r
118 public class Program
\r
120 public static void Main(string[] args)
\r
122 var switchMappings = new Dictionary<string, string>()
\r
126 { "--alt3", "key3" },
\r
127 { "--alt4", "key4" },
\r
128 { "--alt5", "key5" },
\r
129 { "--alt6", "key6" },
\r
131 var builder = new ConfigurationBuilder();
\r
132 builder.AddCommandLine(args, switchMappings);
\r
134 var config = builder.Build();
\r
136 Console.WriteLine($"Key1: '{config["Key1"]}'");
\r
137 Console.WriteLine($"Key2: '{config["Key2"]}'");
\r
138 Console.WriteLine($"Key3: '{config["Key3"]}'");
\r
139 Console.WriteLine($"Key4: '{config["Key4"]}'");
\r
140 Console.WriteLine($"Key5: '{config["Key5"]}'");
\r
141 Console.WriteLine($"Key6: '{config["Key6"]}'");
\r
148 <member name="M:Microsoft.Extensions.Configuration.CommandLineConfigurationExtensions.AddCommandLine(Microsoft.Extensions.Configuration.IConfigurationBuilder,System.Action{Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationSource})">
\r
150 Adds an <see cref="T:Microsoft.Extensions.Configuration.IConfigurationProvider"/> that reads configuration values from the command line.
\r
152 <param name="builder">The <see cref="T:Microsoft.Extensions.Configuration.IConfigurationBuilder"/> to add to.</param>
\r
153 <param name="configureSource">Configures the source.</param>
\r
154 <returns>The <see cref="T:Microsoft.Extensions.Configuration.IConfigurationBuilder"/>.</returns>
\r
156 <member name="T:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider">
\r
158 A command line based <see cref="T:Microsoft.Extensions.Configuration.ConfigurationProvider"/>.
\r
161 <member name="M:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.#ctor(System.Collections.Generic.IEnumerable{System.String},System.Collections.Generic.IDictionary{System.String,System.String})">
\r
163 Initializes a new instance.
\r
165 <param name="args">The command line args.</param>
\r
166 <param name="switchMappings">The switch mappings.</param>
\r
168 <member name="P:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Args">
\r
170 The command line arguments.
\r
173 <member name="M:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Load">
\r
175 Loads the configuration data from the command line args.
\r
178 <member name="T:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationSource">
\r
180 Represents command line arguments as an <see cref="T:Microsoft.Extensions.Configuration.IConfigurationSource"/>.
\r
183 <member name="P:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationSource.SwitchMappings">
\r
185 Gets or sets the switch mappings.
\r
188 <member name="P:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationSource.Args">
\r
190 Gets or sets the command line args.
\r
193 <member name="M:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationSource.Build(Microsoft.Extensions.Configuration.IConfigurationBuilder)">
\r
195 Builds the <see cref="T:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider"/> for this source.
\r
197 <param name="builder">The <see cref="T:Microsoft.Extensions.Configuration.IConfigurationBuilder"/>.</param>
\r
198 <returns>A <see cref="T:Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider"/></returns>
\r
200 <member name="P:Microsoft.Extensions.Configuration.CommandLine.Resources.Error_DuplicatedKeyInSwitchMappings">
\r
201 <summary>Keys in switch mappings are case-insensitive. A duplicated key '{0}' was found.</summary>
\r
203 <member name="M:Microsoft.Extensions.Configuration.CommandLine.Resources.FormatError_DuplicatedKeyInSwitchMappings(System.Object)">
\r
204 <summary>Keys in switch mappings are case-insensitive. A duplicated key '{0}' was found.</summary>
\r
206 <member name="P:Microsoft.Extensions.Configuration.CommandLine.Resources.Error_InvalidSwitchMapping">
\r
207 <summary>The switch mappings contain an invalid switch '{0}'.</summary>
\r
209 <member name="M:Microsoft.Extensions.Configuration.CommandLine.Resources.FormatError_InvalidSwitchMapping(System.Object)">
\r
210 <summary>The switch mappings contain an invalid switch '{0}'.</summary>
\r
212 <member name="P:Microsoft.Extensions.Configuration.CommandLine.Resources.Error_ShortSwitchNotDefined">
\r
213 <summary>The short switch '{0}' is not defined in the switch mappings.</summary>
\r
215 <member name="M:Microsoft.Extensions.Configuration.CommandLine.Resources.FormatError_ShortSwitchNotDefined(System.Object)">
\r
216 <summary>The short switch '{0}' is not defined in the switch mappings.</summary>
\r