Microsoft.Extensions.Configuration.CommandLine Extension methods for registering with . Adds a that reads configuration values from the command line. The to add to. The command line args. The . The values passed on the command line, in the args string array, should be a set of keys prefixed with two dashes ("--") and then values, separate by either the equals sign ("=") or a space (" "). A forward slash ("/") can be used as an alternative prefix, with either equals or space, and when using an equals sign the prefix can be left out altogether. There are five basic alternative formats for arguments: key1=value1 --key2=value2 /key3=value3 --key4 value4 /key5 value5. A simple console application that has five values. // dotnet run key1=value1 --key2=value2 /key3=value3 --key4 value4 /key5 value5 using Microsoft.Extensions.Configuration; using System; namespace CommandLineSample { public class Program { public static void Main(string[] args) { var builder = new ConfigurationBuilder(); builder.AddCommandLine(args); var config = builder.Build(); Console.WriteLine($"Key1: '{config["Key1"]}'"); Console.WriteLine($"Key2: '{config["Key2"]}'"); Console.WriteLine($"Key3: '{config["Key3"]}'"); Console.WriteLine($"Key4: '{config["Key4"]}'"); Console.WriteLine($"Key5: '{config["Key5"]}'"); } } } Adds a that reads configuration values from the command line using the specified switch mappings. The to add to. The command line args. The switch mappings. A dictionary of short (with prefix "-") and alias keys (with prefix "--"), mapped to the configuration key (no prefix). The . The switchMappings allows additional formats for alternative short and alias keys to be used from the command line. Also see the basic version of AddCommandLine for the standard formats supported. Short keys start with a single dash ("-") and are mapped to the main key name (without prefix), and can be used with either equals or space. The single dash mappings are intended to be used for shorter alternative switches. Note that a single dash switch cannot be accessed directly, but must have a switch mapping defined and accessed using the full key. Passing an undefined single dash argument will cause as FormatException. There are two formats for short arguments: -k1=value1 -k2 value2. Alias key definitions start with two dashes ("--") and are mapped to the main key name (without prefix), and can be used in place of the normal key. They also work when a forward slash prefix is used in the command line (but not with the no prefix equals format). There are only four formats for aliased arguments: --alt3=value3 /alt4=value4 --alt5 value5 /alt6 value6. A simple console application that has two short and four alias switch mappings defined. // dotnet run -k1=value1 -k2 value2 --alt3=value2 /alt4=value3 --alt5 value5 /alt6 value6 using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; namespace CommandLineSample { public class Program { public static void Main(string[] args) { var switchMappings = new Dictionary<string, string>() { { "-k1", "key1" }, { "-k2", "key2" }, { "--alt3", "key3" }, { "--alt4", "key4" }, { "--alt5", "key5" }, { "--alt6", "key6" }, }; var builder = new ConfigurationBuilder(); builder.AddCommandLine(args, switchMappings); var config = builder.Build(); Console.WriteLine($"Key1: '{config["Key1"]}'"); Console.WriteLine($"Key2: '{config["Key2"]}'"); Console.WriteLine($"Key3: '{config["Key3"]}'"); Console.WriteLine($"Key4: '{config["Key4"]}'"); Console.WriteLine($"Key5: '{config["Key5"]}'"); Console.WriteLine($"Key6: '{config["Key6"]}'"); } } } Adds an that reads configuration values from the command line. The to add to. Configures the source. The . A command line based . Initializes a new instance. The command line args. The switch mappings. The command line arguments. Loads the configuration data from the command line args. Represents command line arguments as an . Gets or sets the switch mappings. Gets or sets the command line args. Builds the for this source. The . A Throws an if is null. The reference type argument to validate as non-null. The name of the parameter with which corresponds. Throws either an or an if the specified string is or whitespace respectively. String to be checked for or whitespace. The name of the parameter being checked. The original value of . Attribute used to indicate a source generator should create a function for marshalling arguments instead of relying on the runtime to generate an equivalent marshalling function at run-time. This attribute is meaningless if the source generator associated with it is not enabled. The current built-in source generator only supports C# and only supplies an implementation when applied to static, partial, non-generic methods. Initializes a new instance of the . Name of the library containing the import. Gets the name of the library containing the import. Gets or sets the name of the entry point to be called. Gets or sets how to marshal string arguments to the method. If this field is set to a value other than , must not be specified. Gets or sets the used to control how string arguments to the method are marshalled. If this field is specified, must not be specified or must be set to . Gets or sets whether the callee sets an error (SetLastError on Windows or errno on other platforms) before returning from the attributed method. Specifies how strings should be marshalled for generated p/invokes Indicates the user is suppling a specific marshaller in . Use the platform-provided UTF-8 marshaller. Use the platform-provided UTF-16 marshaller. Keys in switch mappings are case-insensitive. A duplicated key '{0}' was found. The switch mappings contain an invalid switch '{0}'. The short switch '{0}' is not defined in the switch mappings. Specifies that null is allowed as an input even if the corresponding type disallows it. Specifies that null is disallowed as an input even if the corresponding type allows it. Specifies that an output may be null even if the corresponding type disallows it. Specifies that an output will not be null even if the corresponding type allows it. Specifies that an input argument was not null when the call returns. Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. Initializes the attribute with the specified return value condition. The return value condition. If the method returns this value, the associated parameter may be null. Gets the return value condition. Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. Initializes the attribute with the specified return value condition. The return value condition. If the method returns this value, the associated parameter will not be null. Gets the return value condition. Specifies that the output will be non-null if the named parameter is non-null. Initializes the attribute with the associated parameter name. The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. Gets the associated parameter name. Applied to a method that will never return under any circumstance. Specifies that the method will not return if the associated Boolean parameter is passed the specified value. Initializes the attribute with the specified parameter value. The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to the associated parameter matches this value. Gets the condition parameter value. Specifies that the method or property will ensure that the listed field and property members have not-null values. Initializes the attribute with a field or property member. The field or property member that is promised to be not-null. Initializes the attribute with the list of field and property members. The list of field and property members that are promised to be not-null. Gets field or property member names. Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition. Initializes the attribute with the specified return value condition and a field or property member. The return value condition. If the method returns this value, the associated parameter will not be null. The field or property member that is promised to be not-null. Initializes the attribute with the specified return value condition and list of field and property members. The return value condition. If the method returns this value, the associated parameter will not be null. The list of field and property members that are promised to be not-null. Gets the return value condition. Gets field or property member names.