简体   繁体   中英

Use external, non native, dll in VS C# class application

I tried to follow some examples but I must be missing something here... I am creating a class application .NET Framework 4. I downloaded a required dll from the internet which I need to reference in my class application.

  1. Should I add it or reference it in my project and how exactly should I do that?
  2. I intend to share the finished dll with others, therefore the external dll I downloaded should be part of my final release - how to I do that?
  3. And how to I use this dll in my class?

Thanks

Case 1: If you have downloaded the dlls from NuGet using your Visual Studio plugin then you do not need to worry about anything.

  • As it will automatically update the package.config in your project
  • It will add the reference for this dlls to your project

Now, at the time of code check-in you should not check-in the dlls files but the package.config file only.

Case 2: If you have downloaded the dlls manually from other sources but not using Visual studio plugin then you will have to manually add the dll reference to your project.

And you should also share these dlls with the code repository. So, that other people do not need to search for it on some other sites.

Case 3: You can upload these dlls to Nuget.org (if security is not a concern) and make it available. in that case this will be one time process and you can just update the package.config as in case 1:

If you want to import a dll to your project, you can refer to the following steps.

1.Click Project => Add Reference...

2.Click Browser => Add the dll your want => Click OK

在此处输入图像描述

3.Add the using statement and call the method that in this dll.

using System;
using testdll;

namespace import_dll
{
    class Program
    {
        static void Main(string[] args)
        {
            // Class1 is the class in testdll.dll
            Class1 class1 = new Class1();
            // Text is the method defined in Class1
            class1.Text();
            Console.ReadKey();
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM