簡體   English   中英

無法引用 SQLite.interop.dll

[英]Unable to reference SQLite.interop.dll

好的,我知道這已經在這里問過幾次了,但沒有任何建議有幫助。 我下載了 SQLite,進入了 bin 並從那里獲取了 DLL。 我正在嘗試發布一個 SQLite 接口,當我編譯並運行時,這就是我得到的

我已經嘗試通過 VS 2015 中的 nuget 管理器手動添加 .DLL。 兩種方式都通過以下錯誤信息。

在此處輸入圖片說明

我在我的智慧盡頭。 我不知道該怎么辦。
這是代碼

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SQLite;

namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            string db = @"URI = file:C:\Users\Mason\Documents\test.db";

            try
            {
                var con = new SQLiteConnection(db);
                con.Open();
                var cmd = new SQLiteCommand(con);

                cmd.CommandText = "select * from test";
                cmd.ExecuteNonQuery();

                Console.Read();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.Read();
            }

        }
    }
}

您不能添加SQLite.Interop.dll作為參考。

好消息是……你不需要。

它只需要可供托管 SQLite 程序集使用。

所以改為這樣做......

將正確的SQLite.Interop.dll版本 (x86,x64) 復制到您的項目文件夾中,並像處理任何文件(圖像、圖標等)一樣將其包含在您的項目中。

然后,在其Properties集中:

Build ActionContent Build Action
Copy to Output DirectoryCopy Always

重建和享受!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM