How to Create a DLL file in .NET Framework using Visual Studio



This article will show how to create a DLL file in .NET framework using Visual Studio.

Creating a dll file

To create a DLL follow the below steps

Open 'Visual Studio' and select File -> Open -> New ->Project

1.gif

Click on OK Button. Once you click on Ok 'Button' your Class Library looks as
follows.

2.gif

Now you can add whatever code that you need to. Here I have String as the return data type for the function. I will use this function in another project (.aspx) and show the Result in a TextBox.

namespace MyClassLibraryConsole
{
public class Class1
{
     
public string strfunction(string input)
{
string strmessage = input;
return strmessage;
}
}
}

Now you have to call this function in another project. Add New (or) Existing Project to your Solution. Here I am adding Existing .asp WebPages to my solution as follows.

3.gif

Once you have added your New or Existing Project your Solution will looks as follows.

4.gif

Adding created dll file in Solution Explorer:

Right click on DllDemo(.asp) solution and click on the select 'Add Reference'.

5.gif

Now you can find dialog Box. Select 3rd tab 'Projects'. Now can find your created ClassLibrary (dll) as 'MyClassLibraryconsole'.Select it and click 'OK' button.

6.gif

Now your dll is added successfully to your website. You can see your added dll in solution Explorer.

7.gif

Calling dll file function in .aspx.cs page:

protected void Button1_Click(object sender, EventArgs e)
{
  MyClassLibraryConsole.
Class1 obj = new MyClassLibraryConsole.Class1();
  TextBox1.Text = obj.strfunction(
"Hellow World");
}

Showing the Result in TextBox:

8.gif

Thanks for Reading my Article!

Shakeer

erver'>