繁体   English   中英

在 VS C# class 应用程序中使用外部的、非本地的 dll

[英]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. 我应该在我的项目中添加它还是引用它,我应该怎么做?
  2. 我打算与其他人分享完成的 dll,因此我下载的外部 dll 应该是我最终版本的一部分 - 我该怎么做?
  3. 以及如何在我的 class 中使用这个 dll?

谢谢

案例 1:如果您使用 Visual Studio 插件从 NuGet 下载了 dll,那么您无需担心任何事情。

  • 因为它会自动更新项目中的 package.config
  • 它将将此 dll 的引用添加到您的项目中

现在,在代码签入时,您不应签入 dll 文件,而应仅签入 package.config 文件。

案例 2:如果您从其他来源手动下载了 dll,但没有使用 Visual Studio 插件,那么您必须手动将 dll 引用添加到您的项目中。

您还应该与代码存储库共享这些 dll。 因此,其他人不需要在其他一些网站上搜索它。

案例 3:您可以将这些 dll 上传到 Nuget.org(如果安全不是问题)并使其可用。 在这种情况下,这将是一次性过程,您可以像案例 1 一样更新 package.config:

如果您想将 dll 导入您的项目,您可以参考以下步骤。

1.点击Project => Add Reference...

2.点击Browser => Add the dll your want =>点击OK

在此处输入图像描述

3.添加using语句,调用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();
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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