先说结论:如果应用程序项目中使用直接引用的形式调用动态链接库,当动态链接库是在调试模式生成的情况下,即使应用程序以发布模式生成,跟随应用程序一同生成的动态链接库仍为调试模式,会引发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查看内部实现。