I want to debug a program in Visual Studio 2008. The problem is that it exits if it doesn't get arguments. This is from the main method:
if (args == null || args.Length != 2 || args[0].ToUpper().Trim() != "RM")
{
Console.WriteLine("RM must be executed by the RSM.");
Console.WriteLine("Press any key to exit program...");
Console.Read();
Environment.Exit(-1);
}
I don't want to comment it out and and then back in when compiling. How can I start the program with arguments when debugging? It is set as the StartUp Project.
My suggestion would be to use Unit Tests.
In your application do the following switches in
Program.cs
:and the same for
static Main(string[] args)
.Or alternatively use Friend Assemblies by adding
to your
AssemblyInfo.cs
.Then create a unit test project and a test that looks a bit like so:
This way you can, in an automated way, test multiple inputs of arguments without having to edit your code or change a menu setting every time you want to check something different.
Go to
Project-><Projectname> Properties
. Then click on theDebug
tab, and fill in your arguments in the textbox calledCommand line arguments
.I would suggest using the directives like the following:
Good luck!