Jim Roberts
Jim Roberts

Reputation: 81

Debugging commandline args in C#

I've built a unit test project for a library in VS 2008 C#. The library will react to commandline arguments. I have set the unit test's Properties -> Debug -> Start Options with default arguments to trigger specific reactions in the target library. My questions are:

1) When the library code executes Environment.GetCommandLineArgs() it does not see any of the default arguments I have set. I have even copied the default arguments from the unit test project to the library project's Properties with no effect. What am I not doing (right)?

2) Is there a programatic way to set the command line arguments? I would like the various tests to be able to set the args and watch the library behavior.

Thank you, Jim

Upvotes: 1

Views: 2853

Answers (2)

Jim Roberts
Jim Roberts

Reputation: 81

Found the problem. The ReSharper add-on is running its TaskRunner.exe to execute the unit tests. The commandline when TaskRunner is invoked does not take the debug settings into account. JetBrains (manufacturer) is now aware of this problem.

Upvotes: 3

Grzenio
Grzenio

Reputation: 36679

it doesn't directly answer your question, but I would recommend not using command line args in a library. Command line args should be parsed by the executable, and then proper parameters passed down to the library. In the case of unit tests you can simply pass test arguments. Think about using your library in a GUI application where the user inputs parameters in a form instead of command line args, or about a program using your library twice in two different ways.

Upvotes: 2

Related Questions