UPDATE: Update to handle colons in setting values.
OK, so here you run into one of the implicit defaults of NDesk.Options, which is that in multivalued parameters, both : and = are considered as value separators, meaning that Setting=C:\Path parses as 3 values (Setting, C, \Path) instead of your expected two.
In order to fix that, you simply have to modify the -s option definition to only consider = as a valid separator, by writing "s={=}" instead of "s=".
Original answer, when it was about backslashes.
I have used NDesk.Options, without encountering any issues with quoted paths and backslashes.
Here is my sample program:
public static void Main(string[] args) { string parsedPath = null; Dictionary<string, string> parsedValues = new Dictionary<string, string>(); var set = new OptionSet() { { "p=", "the project path", v => parsedPath = v }, { "s=", "a setting", (m, v) => { parsedValues.Add(m, v); } }, }; set.Parse(args); Console.WriteLine(parsedPath ?? "<NULL>"); foreach (var keyValuePair in parsedValues) { Console.WriteLine(keyValuePair.Key + "::::" + keyValuePair.Value); } }
You will see that there is a difference between your definition and mine: p= means that the option has a required value, while your definition means that p is a boolean flag value.
I have not run with any problem concerning backslashes, either in the p setting or in the s setting. Could you try running the program with version 0.2.1 of NDesk.Options and show which values fail?
Here are some samples that I ran, which all parsed successfully:
-p=..\Path -p..\Path -pC:\Hello -pHello\World -p"Hello\World" -s"Greeting=Hello\World" -sGreeting="Hello\World" -sGreeting=Hello\World -sGreeting="Hello\My World" -s"Greeting=Hello\My World"
Here are some parses which do produce another result that deserve mention:
-sGreeting=Hello\My World -- // This gives Greeting="Hello\My"
Note: If that changes anything, I ran NDesk.Options with the Options.cs source code file in the project, not with the compiled DLL.