簡體   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