UPDATE : update to handle colons in settings.
OK, so here you are faced with one of the implicit values โโof NDesk.Options , which is in multi-valued parameters, like : and = treated as value separators, which means that Setting=C:\Path analyzes as 3 values โโ(Setting, C, \ Path) instead of the expected two.
To fix this, you just need to change the definition of the -s option to treat = as a valid delimiter by writing "s={=}" instead of "s=" .
The original answer when it came to the backslash.
I used NDesk.Options without encountering any problems with the specified tracks 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 parameter has the required value, while your definition means that p is the value of the Boolean flag.
I had no problems with backslashes, both in setting p and setting s. Could you try to run the program with version 0.2.1 of NDesk.Options and show which values โโfail?
Here are a few examples that I followed that all successfully analyzed:
-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 of the analyzes that lead to another result that deserves mention:
-sGreeting=Hello\My World -- // This gives Greeting="Hello\My"
Note. If this changes something, I ran NDesk.Options with the source code of the Options.cs file in the project, and not with the compiled DLL.