先說結論:如果應用程序項目中使用直接引用的形式調用動態鏈接庫,當動態鏈接庫是在調試模式生成的情況下,即使應用程序以發布模式生成,跟隨應用程序一同生成的動態鏈接庫仍為調試模式,會引發DLL實現泄露問題;當動態鏈接庫是在發布模式生成,則不論應用程序的生成模式,都無法通過跟隨應用程序一同生成的動態鏈接庫查看內部實現細節,需注意。
實驗條件:
兩個控制臺工程,一個類庫工程。
類庫工程內容如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ClassLibrary1
{public class Class1{public void ConsoleWriteLineA(){Console.WriteLine("A");}}
}
?控制臺工程內容如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApp1
{internal class Program{static void Main(string[] args){ClassLibrary1.Class1 class1 = new ClassLibrary1.Class1();class1.ConsoleWriteLineA();Console.Read();}}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApp2
{internal class Program{static void Main(string[] args){ClassLibrary1.Class1 class1 = new ClassLibrary1.Class1();class1.ConsoleWriteLineA();Console.Read();}}
}
實驗步驟:
在調試模式下生成DLL,在Exe1項目中直接引用DLL,在發布模式下生成Exe1,此時Exe1的默認生成路徑下內容如下:
在Exe2項目中調用Exe1默認生成路徑下的DLL,此時進行Exe2項目調試時,能夠通過DLL方法查看DLL內部實現。
如果將Exe1項目中直接引用的DLL改為發布模式下生成的DLL,再以Exe2項目直接引用Exe1默認生成路徑下的DLL,則會彈窗:
也無法進入DLL查看內部實現。