Sanmathi
Sanmathi

Reputation: 131

C# Executable project (console app) for a test project

I have a test project which is a library. I want to write a console application to be able to reference the DLL of the test project and call the methods and classes from my test project.

Also while writing the console app, I want to how to execute the exe from command prompt with parameters. My console app code should take in the input I give and execute the tests.

I just need some example code, so that I can pick it up from there.

Upvotes: 0

Views: 1211

Answers (1)

Leonel Maye
Leonel Maye

Reputation: 121

You have to follow these steps:

  1. Add your DLL file as reference to your console project. Project>>Add Reference>>Browse and select your dll file.
  2. add usign myNamespaceOfMyDll;
  3. Then in your code you can use the methods from your dll file.

Sample (Using the GMmap's dll):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GMap.NET;
usign myNamespace;
namespace ConsoleApplication6
{
   class Program
   {
      static void Main(string[] args)
      {
        //GPoint is a user data type declared in GMap.NET
        //method is a method definied in myNamespace (your dll)
        GPoint s=method(param1,param2);
      }
   }
 }

Suppose that you have the next code, you have to add an array of strings as param in your main method.

using System;
class Program
{
  static void Main(string[] args)
  {
if (args == null)
{
    Console.WriteLine("args is null"); // Check for null array
}
else
{
   //Here you can to use then content of your args array.
}
Console.ReadLine();
  }
}

Thus if you type:

c:\> myApp param1 param2

args[0]="param1", args[1]="param2", and the length of the array is 2.

Upvotes: 1

Related Questions