Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a .dll file in C#.Net

Tags:

c#

.net

file

dll

I had created a project which is C# console application project for which I need to call this project dll in another windows application project. I had built the project in visual studio 2010 and checked for .dll file in bin\debug folder, but it is not created.

But a manifest file and .exe file havebeen created. Please help me out how to create the .dll in this case?

like image 378
Ambarish Avatar asked Mar 22 '13 10:03

Ambarish


People also ask

What is DLL in C programming?

In Windows, a dynamic-link library (DLL) is a kind of executable file that acts as a shared library of functions and resources. Dynamic linking is an operating system capability. It enables an executable to call functions or use resources stored in a separate file.

What language is DLL written in?

DLL's were conceived before C++ came into mainstream use. They were created for the C language. You can write DLL's with C++ but you'll be able to easily use them only from applications that were written with the same version of the same compiler as the DLL.

When DLL file is created in C#?

A Dynamic Link library (DLL) is a library that contains functions and codes that can be used by more than one program at a time. Once we have created a DLL file, we can use it in many applications. The only thing we need to do is to add the reference/import the DLL File.


4 Answers

You need to make a class library and not a Console Application. The console application is translated into an .exe whereas the class library will then be compiled into a dll which you can reference in your windows project.

  • Right click on your Console Application -> Properties -> Change the Output type to Class Library

enter image description here

like image 60
Darren Avatar answered Oct 18 '22 09:10

Darren


To create a DLL File, click on New project, then select Class Library.

Enter your code into the class file that was automatically created for you and then click Build Solution from the Debug menu.

Now, look in your directory: ../debug/release/YOURDLL.dll

There it is! :)

P.S. DLL files cannot be run just like normal applciation (exe) files. You'll need to create a separate project (probably a win forms app) and then add your dll file to that project as a "Reference", you can do this by going to the Solution explorer, right clicking your project Name and selecting Add Reference then browsing to whereever you saved your dll file.

For more detail please click HERE

like image 26
Rohit Vyas Avatar answered Oct 18 '22 11:10

Rohit Vyas


You need to change project settings. Right click your project, go to properites. In Application tab change output type to class library instead of Windows application.

like image 36
fhnaseer Avatar answered Oct 18 '22 09:10

fhnaseer


Console Application is an application (.exe), not a Library (.dll). To make a library, create a new project, select "Class Library" in type of project, then copy the logic of your first code into this new project.

Or you can edit the Project Properties and select Class Library instead of Console Application in Output type.

As some code can be "console" dependant, I think first solution is better if you check your logic when you copy it.

like image 20
Xaruth Avatar answered Oct 18 '22 10:10

Xaruth