Sanmathi
Sanmathi

Reputation: 131

Code in C# for a console application project that consumes a dll from another project

I am using visual studio for this. I have test project which generates a dll and runs the different tests everytime I build the project. Now i want to write a console application which generates an exe that consumes the dll generated above. Can I do it using dllImport? If yes, please tell me how?

Upvotes: 0

Views: 1275

Answers (3)

markmnl
markmnl

Reputation: 11426

You just need to:

  1. Add the test project in the same solution then, enter image description here
  2. add reference to project from your console application. enter image description here

Now when you build the solution the library project will built first and its .dll will automatically be included in the bin directory of you console project. The advantage of doing this instead of referencing just the built .dll is you can modify and debug the source of your library project, e.g. step into it's methods.

However you can just do the second step and instead of adding a reference to your project browse to to the built .dll and add that as a reference.

Upvotes: 2

user1968030
user1968030

Reputation:

You can add reference :

In Solution Explorer, right-click the project node and click Add Reference.

In the Add Reference dialog box, select the tab indicating the type of component you want to reference.

Select the components you want to reference, and then click OK.

enter image description here

Upvotes: 0

bit
bit

Reputation: 4487

You can either

  1. Add the test project in the same solution then,
  2. Add reference to project from your console application.

OR

  1. Include a folder named Tests into your console app.
  2. Add the test dll generated in it.
  3. Add reference to project from your console application.

Upvotes: 0

Related Questions