다음을 통해 공유


Visual Studio: Creating a portable class library

This articles is how you can create your own .dll file in order to get your own functionality into the file, which can be used further in future or you can share it online to help others.

Why we need .dll?

So, the question arises, why we need to create .dll. With this very file, you don't need to write same functions again and again in order to get the same result. So, what we do, we create .dll, add the required class with required function to perform specific tasks and save it into dll form. which can be used later in other projects or you can share it with others so that they don't need to write same functions again.

Procedure:

follow the following steps in order to achieve your functionality in .dll form:

  1. create project with C# in windows form application.

  2. Add the Base Class Library(Portable) project in your solution. 

  3. Now, select your required frameworks in which you want to use your new defining Base Class Library(BCL) eg: silverlight, windows phone 8.1, IOS or etc.

  4. Click OK.

  5. you will see a new project is added into the solution of your solution explorer

  6. Copy this class and name it whatever you want.

  7.  

    public class  Class1
       {
           public int  add(int  a, int  b) 
           {
               return a + b; 
           }
       }
    

         

  8. Now that you have added your project and code in it. Compile the code in order to get the dll.

  9. The dll will be saved in the bin folder of project folder.

So, this is how one can create a portable class library which can be used at any platform or framework as you mentioned. In order to use it into one of your another object simply add the reference of your dll into your new project and access the methods by simply creating and calling a method from object.